This repository was archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.yml
More file actions
301 lines (257 loc) · 7.66 KB
/
bootstrap.yml
File metadata and controls
301 lines (257 loc) · 7.66 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
---
# TODO: proper permissions (users and groups + sudo)
- name: Bootstrap RPi LoRaWAN Basic Station gateway
hosts: all
remote_user: alarm
become: yes
become_method: su
become_user: root
gather_facts: no
# https://blog.knoldus.com/how-to-install-python-in-target-host-using-ansible/
pre_tasks:
- name: Check vars
assert:
that:
- gateway_name != ""
- name: Initialize pacman keyring
raw: pacman-key --init
ignore_errors: yes
- name: Populate ARM
raw: pacman-key --populate archlinuxarm
ignore_errors: yes
- name: Update mirrors
raw: pacman -Syy --noconfirm
ignore_errors: yes
- name: Install Python
raw: pacman -S --noconfirm --needed python
ignore_errors: yes
tasks:
- name: Install boot config
ansible.builtin.copy:
src: ./sys/config.txt
dest: /boot/config.txt
- name: Install kernel cmdline args
ansible.builtin.copy:
src: ./sys/cmdline.txt
dest: /boot/cmdline.txt
- name: Update system
community.general.pacman:
update_cache: yes
upgrade: yes
- name: Install packages
community.general.pacman:
state: present
name:
- inetutils
- python-pip
- sudo
- man
- ntp
- jq
- gcc
- devtools
- binutils
- make
- cmake
- glibc
- usbutils
- coreutils
- curl
- gzip
- iw
- elfutils
- findutils
- raspberrypi-firmware
- i2c-tools
- lm_sensors
- cronie
- tmux
- neovim
- dnsmasq
- dhcpcd
- nodejs
- npm
- hostapd
- name: Install Python dependencies
ansible.builtin.pip:
name:
- pynmea2
- name: Install root tool configs
ansible.builtin.copy:
src: "./sys/{{ item }}"
dest: "~/{{ item }}"
loop:
- .tmux.conf
- name: Install user "alarm" tool configs
ansible.builtin.copy:
src: "./sys/{{ item }}"
dest: "/home/alarm/{{ item }}"
loop:
- .tmux.conf
- name: Enable systemd services
ansible.builtin.systemd:
enabled: yes
state: started
name: "{{ item }}"
loop:
- cronie
- name: Set to UTC
ansible.builtin.shell: |
timedatectl set-timezone UTC
timedatectl set-ntp true
- name: Set as default locale
command: localectl set-locale LANG=en_US.UTF-8
- name: Reboot system for changes to take effect
ansible.builtin.reboot:
- name: Install Basic Station
hosts: all
remote_user: alarm
become: yes
become_method: su
become_user: root
vars:
install_path: /etc/aether
tasks:
- name: Set gateway EUI
when: gw_eui is undefined
block:
- name: Generate gateway EUI
ansible.builtin.script: ./scripts/geneui.sh
register: eui
- name: Set fact
set_fact:
gw_eui: "{{ eui.stdout | trim }}"
- name: Gateway EUI
debug:
msg: "{{ gw_eui }}"
- name: Install Basic Station
ansible.builtin.script: ./scripts/install-basicstation.sh
args:
creates: /usr/bin/station
- name: Create aether config directory /etc/aether/
ansible.builtin.file:
path: "{{ install_path }}"
recurse: true
state: directory
- name: Install templated station config
ansible.builtin.template:
src: ./gateway/station.j2
dest: "{{ install_path }}/station.conf"
- name: Install remaining station config
ansible.builtin.copy:
src: "./gateway/{{ item }}"
dest: "{{ install_path }}/{{ item }}"
loop: [version.txt]
- name: Create scripts directory
ansible.builtin.file:
path: "{{ install_path }}/scripts/"
recurse: true
state: directory
- name: Install station scripts
ansible.builtin.copy:
src: "./gateway/scripts/{{ item }}"
dest: "{{ install_path }}/scripts/{{ item }}"
mode: '755'
loop: ['init.sh', 'gps.py']
- name: Setup Gateway GPS cronjob
ansible.builtin.cron:
name: "Update gateway GPS location"
minute: "15"
job: "python {{ install_path }}/scripts/gps.py"
- name: Make Basic Station command FIFO
ansible.builtin.shell: "mkfifo {{ install_path }}/cmd.fifo"
ignore_errors: yes
- name: Install Basic Station service
ansible.builtin.copy:
src: ./gateway/basicstation.service
dest: /etc/systemd/system/basicstation.service
- name: Configure with AWS
block:
- name: Checking if gateway already exists
ansible.builtin.shell: "./scripts/aws-does-gw-exist.sh {{ gw_eui }}"
register: gateway_exists
# TODO: Add prompt later
- name: Updating existing gateway with AWS
ansible.builtin.script: ./scripts/aws-register-gateway.sh
environment:
EXISTS: "1"
when: "'true' in gateway_exists.stdout"
- name: Register gateway with AWS
ansible.builtin.script: ./scripts/aws-register-gateway.sh
when: "'false' in gateway_exists.stdout"
when: aws_register is undefined or aws_register is truthy
become: yes
become_user: "{{ lookup('env', 'USER') }}"
delegate_to: localhost
environment:
GATEWAY_EUI: "{{ gw_eui }}"
GATEWAY_NAME: "{{ gateway_name }}"
AWS_REGION: us-east-1
- name: Installing AWS secrets
ansible.builtin.copy:
src: "./{{ item }}"
dest: "{{ install_path }}/{{ item }}"
loop: ['cups.crt', 'cups.key', 'cups.trust', 'cups.uri', 'lns.trust', 'lns.uri']
when: aws_register is undefined or aws_register is truthy
- name: Start Basic Station service
ansible.builtin.systemd:
name: basicstation
daemon_reload: yes
enabled: yes
state: started
masked: no
- name: Configure networking tools
hosts: all
remote_user: alarm
become: yes
become_method: su
become_user: root
tasks:
# Disable dns stub listener
# Add fallback DNSes
# Default file has these commented out under [Resolve]
- name: Configure systemd-resolved and systemd-networkd
ansible.builtin.shell: |
sed -E -i 's/#(DNSStubListener=)yes/\1no/' /etc/systemd/resolved.conf
sed -E -i 's/#(FallbackDNS.*)/\1/' /etc/systemd/resolved.conf
systemctl restart systemd-resolved
systemctl disable systemd-networkd
- name: Download and install raspberry-wifi-conf tool
args:
creates: /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
ansible.builtin.shell: |
cd /root
git clone https://github.com/UCF-Aether/raspberry-wifi-conf.git
cd raspberry-wifi-conf
npm i -g bower
npm install
npm update
bower install
npm run install:timer
echo "update_config=1
country=US
network={
}" > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
systemctl enable wifi-ap-mon.timer
- name: Enable systemd services
ansible.builtin.systemd:
daemon_reload: true
enabled: yes
state: started
name: "{{ item }}"
loop:
- dnsmasq
- dhcpcd
- hostapd
- wpa_supplicant@wlan0
- name: Restart systemd services for sanity
ansible.builtin.systemd:
daemon_reload: true
enabled: yes
state: restarted
name: "{{ item }}"
loop:
- dnsmasq
- dhcpcd
- hostapd
- wpa_supplicant@wlan0