-
-
Notifications
You must be signed in to change notification settings - Fork 593
/
main.yml
325 lines (285 loc) · 8.22 KB
/
main.yml
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
---
- name: Create a config_path variable
ansible.builtin.set_fact:
config_path: "{{ '/boot/config.txt' if ansible_distribution_major_version|int <= 11 else '/boot/firmware/config.txt' }}"
cmdline_path: "{{ '/boot/cmdline.txt' if ansible_distribution_major_version|int <= 11 else '/boot/firmware/cmdline.txt' }}"
- name: Check NOOBS
ansible.builtin.command: cat {{ config_path }}
register: config_txt
changed_when: false
tags:
- touches_boot_partition
- name: Make sure we have proper framebuffer depth
ansible.builtin.lineinfile:
dest: "{{ config_path }}"
regexp: ^framebuffer_depth=
line: framebuffer_depth=32
tags:
- touches_boot_partition
- name: Fix framebuffer bug
ansible.builtin.lineinfile:
dest: "{{ config_path }}"
regexp: ^framebuffer_ignore_alpha=
line: framebuffer_ignore_alpha=1
tags:
- touches_boot_partition
- name: Add gpu_mem_256 in config.txt if it doesn't exist
ansible.builtin.lineinfile:
path: "{{ config_path }}"
line: gpu_mem_256=96
when: config_txt.stdout.find('gpu_mem_256') == -1
tags:
- touches_boot_partition
- name: Add gpu_mem_512 in config.txt if it doesn't exist
ansible.builtin.lineinfile:
path: "{{ config_path }}"
line: gpu_mem_512=128
when: config_txt.stdout.find('gpu_mem_512') == -1
tags:
- touches_boot_partition
- name: Add gpu_mem_1024 in config.txt if it doesn't exist
ansible.builtin.lineinfile:
path: "{{ config_path }}"
line: gpu_mem_1024=196
when: config_txt.stdout.find('gpu_mem_1024') == -1
tags:
- touches_boot_partition
- name: Add pi4 section in config.txt if it doesn't exist
ansible.builtin.lineinfile:
path: "{{ config_path }}"
line: "[pi4]"
when: config_txt.stdout.find('[pi4]') == -1
- name: Comment out the original dtoverlay config.
ansible.builtin.replace:
dest: "{{ config_path }}"
regexp: ^(dtoverlay=vc4-kms-v3d)$
replace: '#\1'
- name: Add FKMS config for Pi 4. (<= Debian 11)
ansible.builtin.lineinfile:
path: "{{ config_path }}"
insertafter: '^\[pi4\]$'
line: dtoverlay=vc4-fkms-v3d
when:
- ansible_distribution_major_version|int <= 11
- name: Add FKMS config for Pi 4. (>= Debian 12)
ansible.builtin.lineinfile:
path: "{{ config_path }}"
insertafter: '^\[pi4\]$'
line: dtoverlay=vc4-fkms-v3d
when:
- ansible_distribution_major_version|int >= 12
- name: Backup kernel boot args
ansible.builtin.copy:
src: "{{ cmdline_path }}"
dest: "{{ cmdline_path }}.orig"
owner: root
group: root
mode: "0755"
force: false
tags:
- touches_boot_partition
- name: Notice for cmdline.txt.orig file
ansible.builtin.debug:
msg: "Use cmdline.txt.orig for boot parameters (don't remove this file)"
- name: Copy cmdline.txt.orig to cmdline.txt
ansible.builtin.copy:
src: "{{ cmdline_path }}.orig"
dest: "{{ cmdline_path }}"
owner: root
group: root
mode: "0755"
force: true
when: config_txt.stdout.find('NOOBS') == -1
tags:
- touches_boot_partition
- name: For splash screen using Plymouth
ansible.builtin.replace:
dest: "{{ cmdline_path }}"
regexp: (^(?!$)((?!splash).)*$)
replace: \1 splash
when: ansible_distribution_major_version|int >= 7
- name: Remove blinking cursor
ansible.builtin.replace:
dest: "{{ cmdline_path }}"
regexp: (^(?!$)((?!vt.global_cursor_default=0).)*$)
replace: \1 vt.global_cursor_default=0
when: ansible_distribution_major_version|int >= 7
tags:
- touches_boot_partition
- name: Plymouth ignore serial consoles
ansible.builtin.replace:
dest: "{{ cmdline_path }}"
regexp: (^(?!$)((?!plymouth.ignore-serial-consoles).)*$)
replace: \1 plymouth.ignore-serial-consoles
when: ansible_distribution_major_version|int >= 7
tags:
- touches_boot_partition
- name: Use Systemd as init and quiet boot process
ansible.builtin.replace:
dest: "{{ cmdline_path }}"
regexp: (^(?!$)((?!quiet init=/lib/systemd/systemd).)*$)
replace: \1 quiet init=/lib/systemd/systemd
tags:
- touches_boot_partition
- name: Set ethN/wlanN names for interfaces
ansible.builtin.replace:
dest: "{{ cmdline_path }}"
regexp: (^(?!$)((?!net\.ifnames=0).)*$)
replace: \1 net.ifnames=0
tags:
- touches_boot_partition
- name: Set cgroup_enable required by containerd for OOM
ansible.builtin.replace:
dest: "{{ cmdline_path }}"
regexp: (^(?!$)((?!cgroup_enable=memory).)*$)
replace: \1 cgroup_enable=memory
when: ansible_distribution_major_version|int >= 7
tags:
- touches_boot_partition
- name: Set cgroup_memory required by containerd for OOM
ansible.builtin.replace:
dest: "{{ cmdline_path }}"
regexp: (^(?!$)((?!cgroup_memory=1).)*$)
replace: \1 cgroup_memory=1
when: ansible_distribution_major_version|int >= 7
tags:
- touches_boot_partition
# Sometimes in some packages there are no necessary files.
# They are required to install pip dependencies.
# In this case we need to reinstall the packages.
- name: Check if cdefs.h exists
ansible.builtin.stat:
path: /usr/include/arm-linux-gnueabihf/sys/cdefs.h
register: cdefs
- name: Set fact for cdefs
ansible.builtin.set_fact:
cdefs_exist: "{{ cdefs.stat.exists }}"
- name: Remove libc6-dev
ansible.builtin.apt:
name: libc6-dev
state: absent
when: not cdefs_exist
- name: Install libc6-dev
ansible.builtin.apt:
name: libc6-dev
state: present
update_cache: true
when: not cdefs_exist
- name: Install Screenly dependencies
ansible.builtin.apt:
name:
- rpi-update
- bc
- python3
- python3-redis
state: present
- name: Remove deprecated apt dependencies
ansible.builtin.apt:
name:
- dphys-swapfile
- lightdm
- lightdm-gtk-greeter
- matchbox
- nginx-common
- nginx-light
- pix-plym-splash
- rabbitmq-server
- redis-server
- supervisor
- uzbl
- x11-xserver-utils
- xserver-xorg
state: absent
- name: Make sure distro package of Docker is absent
ansible.builtin.apt:
name:
- docker
- docker-engine
- docker.io
- containerd
- runc
- docker-compose
state: absent
- name: Add docker apt key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/raspbian/gpg
state: present
- name: Get raspbian name
ansible.builtin.command: lsb_release -cs
register: raspbian_name
changed_when: false
- name: Add Docker repo
ansible.builtin.lineinfile:
path: /etc/apt/sources.list.d/docker.list
create: true
line: "deb [arch=armhf] https://download.docker.com/linux/debian {{ raspbian_name.stdout }} stable"
state: present
owner: root
group: root
mode: "0644"
- name: Install Docker
ansible.builtin.apt:
name:
- docker-ce:armhf
- docker-ce-cli:armhf
- docker-compose-plugin:armhf
update_cache: true
install_recommends: false
- name: Add user to docker group
ansible.builtin.user:
name: "{{ lookup('env', 'USER') }}"
group: "{{ lookup('env', 'USER') }}"
groups:
- docker
- adm
- sudo
- video
- plugdev
- users
- input
- netdev
- gpio
- dialout
- name: Perform system upgrade
ansible.builtin.apt:
upgrade: dist
tags:
- system-upgrade
- name: Clean up unused packages
ansible.builtin.apt:
autoremove: true
tags:
- system-upgrade
- name: Remove deprecated pip dependencies (<= Debian 11)
ansible.builtin.pip:
name: supervisor
state: absent
when:
- ansible_distribution_major_version|int <= 11
- name: Remove deprecated pip dependencies (>= Debian 12)
ansible.builtin.pip:
name: supervisor
executable: /home/{{ lookup('env', 'USER') }}/installer_venv/bin/pip
state: absent
when:
- ansible_distribution_major_version|int >= 12
- name: Copy in rc.local
ansible.builtin.copy:
src: rc.local
dest: /etc/rc.local
mode: "0755"
owner: root
group: root
- name: Copy in 01_nodoc
ansible.builtin.copy:
src: 01_nodoc
dest: /etc/dpkg/dpkg.cfg.d/01_nodoc
mode: "0644"
owner: root
group: root
- name: Disable swap
ansible.builtin.command: /sbin/swapoff --all removes=/var/swap
- name: Remove swapfile from disk
ansible.builtin.file:
path: /var/swap
state: absent