-
Notifications
You must be signed in to change notification settings - Fork 3
/
system.yaml
113 lines (99 loc) · 2.96 KB
/
system.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
- hosts: localhost
become: true
vars:
source_dir: "/home/pi/raspberrypi-iot" # replace with your source directory
tasks:
- name: Install base packages
apt:
name: "{{ packages }}"
vars:
packages:
- dnsmasq
- hostapd
- nginx
- python3-pip
- python3-venv
## Wifi access point configuration ##
# this will not overwrite your existing files
- name: Copy wpa_supplicant files
copy:
src: "{{ source_dir }}/system/etc/wpa_supplicant/{{ item }}"
dest: /etc/wpa_supplicant/
force: no
remote_src: yes
with_items:
- 'wpa_supplicant-wlan1.conf'
- 'wpa_supplicant.conf'
- name: Make wpa_supplicant files owned by pi
file:
path: '/etc/wpa_supplicant'
owner: pi
recurse: yes
# hostapd became masked, see https://github.com/raspberrypi/documentation/issues/1018
- name: Stop hostapd and dnsmasq for now
systemd:
state: stopped
name: "{{ item }}"
masked: 'no'
with_items:
- hostapd
- dnsmasq
- name: Copy configuration files into /etc
copy:
src: "{{ source_dir }}/system/etc/{{ item }}"
dest: /etc/
remote_src: yes
with_items:
- dhcpcd.conf
- dnsmasq.conf
- sysctl.conf
- iptables.ipv4.nat
- rc.local
- hosts
- hostname
- name: Configure hostapd
copy:
src: '{{ source_dir }}/system/etc/hostapd/hostapd.conf'
dest: /etc/hostapd/hostapd.conf
remote_src: yes
- name: Point system to hostapd configuration file
copy:
src: '{{ source_dir }}/system/etc/default/hostapd'
dest: /etc/default/hostapd
remote_src: yes
- name: Restart services
systemd:
name: "{{ item }}"
state: restarted
with_items:
- dhcpcd
- hostapd
- dnsmasq
## Install frontend and backend ##
- name: Copy nginx configuration file
template: src={{ source_dir }}/system/etc/nginx/sites-available/default.j2 dest=/etc/nginx/sites-available/default
- name: Create a virtual environment for backend dependencies
pip:
requirements: '{{ source_dir }}/backend/requirements.txt'
virtualenv: '{{ source_dir }}/backend/venv'
virtualenv_command: /usr/bin/python3 -m venv
- name: Install backend service
template:
src: '{{ source_dir }}/system/etc/systemd/system/rpi-iot-backend.service.j2'
dest: /etc/systemd/system/rpi-iot-backend.service
- name: Start and enable backend service
systemd:
state: restarted
enabled: yes
name: 'rpi-iot-backend'
daemon_reload: yes
- name: Reload nginx
systemd:
state: restarted
name: nginx
- name: Make sure hostapd is enabled at the end
systemd:
name: hostapd
state: started
enabled: yes