-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplaybook.yaml
402 lines (347 loc) · 9.65 KB
/
playbook.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
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
---
- hosts: all
become: true
remote_user: mirror
handlers:
- import_tasks: handlers.yaml
tasks:
- name: "Load OS specific vault"
include_vars: vault/common.yml
- name: "Load OS specific vault"
include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- "{{ ansible_hostname|lower }}.yml"
- default.yml
paths:
- 'vault'
- name: Enable EPEL
dnf:
name: epel-release
state: latest
- name: Enable copr warthog9/epel8-missing-pieces
include_role:
name: devnullcake.copr-repository
vars:
copr_repository: "warthog9/epel8-missing-pieces"
copr_repository_action: "install"
when:
ansible_distribution != 'Fedora'
and
(
ansible_distribution_file_variety == 'RedHat'
or
ansible_distribution == 'CentOS'
or
ansible_distribution == 'Red Hat Enterprise Linux'
)
and
ansible_facts['distribution_major_version']|int == 8
- name: Enable copr warthog9/epel9-missing-pieces
include_role:
name: devnullcake.copr-repository
vars:
copr_repository: "warthog9/epel9-missing-pieces"
copr_repository_action: "install"
when:
ansible_distribution != 'Fedora'
and
(
ansible_distribution_file_variety == 'RedHat'
or
ansible_distribution == 'CentOS'
or
ansible_distribution == 'Red Hat Enterprise Linux'
)
and
ansible_facts['distribution_major_version']|int == 9
- name: Enable rsync backports repo
ansible.builtin.yum_repository:
name: backports-rsync
description: AlmaLinux Backports - rsync
file: almalinux-rsync
baseurl: http://repo.almalinux.org/backports/$releasever/$basearch/rsync/
gpgcheck: yes
gpgkey:
- file:///etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux
- file:///etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux-9
- name: Install required software
package:
state: present
name:
- byobu
- certbot
- cockpit
- cockpit-ws
- dnf-automatic
- dstat
- duperemove
- gnutls
- lldpd
- mosquitto
- net-tools
- pciutils
- postfix
- python3-certbot-nginx
- python3-policycoreutils
- policycoreutils-python-utils
- rsync
- rsync-daemon
- rsyslog-gnutls
- screen
- smartmontools
- tcpdump
- traceroute
- vim
- wget
- whois
- name: Postfix make sure devnull@localhost exists
include_role:
name: repleo.aliases
vars:
aliases:
- user: devnull
alias: /dev/null
- name: Enable postfix service
systemd:
name: postfix.service
state: started
enabled: yes
- name: Install required software
package:
state: present
name:
- '@nginx:1.20/common'
when:
ansible_facts['distribution_major_version']|int == 8
- name: Install required software
package:
state: present
name:
- nginx
- nginx-mod-http-xslt-filter
when:
ansible_facts['distribution_major_version']|int == 9
- name: Update all software
dnf:
state: latest
name: "*"
- name: Set timezone
timezone:
name: America/Los_Angeles
- name: Install SSH keys
authorized_key:
user: mirror
state: present
key: '{{ main_ssh_keys }}'
loop_control:
loop_var: main_ssh_keys
loop:
with_items:
- https://github.com/phirephly.keys
- https://github.com/warthog9.keys
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDbALSrSqVWdZfxIkUv7aSX4c1Qd96bFED3JyPv7fx2O Warthog9gandalfWSL"
- name: Enable sshd_config.d on EL8
copy:
src: files/sshd_config.el8
dest: /etc/ssh/sshd_config
when:
ansible_facts['distribution_major_version']|int == 8
notify:
- reload sshd
- name: Install sshd config snippets
copy:
src: files/sshd_config.d
dest: /etc/ssh/
notify:
- reload sshd
- name: Check if TLS is already setup - ssl options
stat:
path: /etc/letsencrypt/options-ssl-nginx.conf
register: letsencrypt_nginx_options
- name: Check if TLS is already setup - actual certificate
stat:
path: /etc/letsencrypt/live/{{ansible_nodename}}/fullchain.pem
register: ssl_cert_fullchain
- name: Ok lets setup letsencrypt quick
set_fact: tls_setup=True
- name: Ok lets setup letsencrypt quick
set_fact: tls_setup=False
when:
not letsencrypt_nginx_options.stat.exists
or
not ssl_cert_fullchain.stat.exists
- name: Configure Nginx - NO TLS
template:
src: templates/nginx.conf
dest: /etc/nginx/nginx.conf
notify:
- reload nginx
when: not tls_setup
- name: Install Nginx index template
template:
src: templates/autoindex.xslt
dest: /usr/share/nginx/html/autoindex.xslt
notify:
- reload nginx
- name: Install HTTP Favicon
copy:
src: files/favicon.ico
dest: /usr/share/nginx/html/favicon.ico
- name: Install HTTP Robots.txt
copy:
src: files/robots.txt
dest: /usr/share/nginx/html/robots.txt
- name: Start NGINX without TLS
service:
name: nginx
state: reloaded
enabled: yes
ignore_errors: yes
when: not tls_setup
- name: Snag SSL cert
command: /usr/bin/certbot -d {{ansible_nodename}} --nginx --non-interactive --agree-tos -m [email protected]
when: not tls_setup
ignore_errors: true
register: certbot_status
- name: Ok lets setup letsencrypt quick
set_fact: tls_setup=True
when:
not tls_setup
and
certbot_status.rc == 0
# run this after we've done all the bits to make this work
- name: Configure Nginx
template:
src: templates/nginx.conf
dest: /etc/nginx/nginx.conf
notify:
- reload nginx
when: tls_setup
- name: Configure nftables firewall
template:
src: templates/nftables.conf
dest: /etc/sysconfig/nftables.conf
notify: reload firewall
- name: Disable firewalld
service:
name: firewalld
state: stopped
enabled: no
- name: Enable nftables
service:
name: nftables
state: started
enabled: yes
- name: Copy over sysctl IP stack optimizations
copy:
src: files/sysctl.performancetune.conf
dest: /etc/sysctl.d/50-performancetune.conf
notify: reload sysctl
- name: Install Update Script
template:
src: templates/update-mirror.sh
dest: /usr/local/bin/update-mirror.sh
mode: '0755'
- name: Schedule cron tasks
copy:
src: "{{ item }}"
dest: /etc/cron.d/
with_fileglob: files/cron.d/*
- name: Create Mirror Data Dir
file:
path: /data/mirror
state: directory
owner: mirror
group: mirror
- name: Create Mirror Log Dir
file:
path: /var/log/mirror
state: directory
owner: mirror
group: mirror
- name: Create Mirror Lock Dir
file:
path: /home/mirror/lock
state: directory
owner: mirror
group: mirror
- name: Configure Rsyncd
template:
src: templates/rsyncd.conf
dest: /etc/rsyncd.conf
- name: Enable rsyncd
service:
name: rsyncd
state: started
enabled: yes
- name: Install mqtt-exec
copy:
src: files/mqtt-exec
dest: /usr/local/bin/mqtt-exec
mode: '0755'
- name: Install mqtt-exec service unit
copy:
src: files/systemd.mqtt-exec.service
dest: /etc/systemd/system/mqtt-exec.service
- name: Enable mqtt-exec service
systemd:
name: mqtt-exec.service
state: started
enabled: yes
- name: Enable LLDP
service:
name: lldpd
state: started
enabled: yes
- name: Install chronyd config file
copy:
src: files/chrony.conf
dest: /etc/chrony.conf
notify: restart chrony
- name: Enable chronyd service
systemd:
name: chronyd.service
state: started
enabled: yes
- name: Setup fail2ban
include_role:
name: fail2ban
- name: fail2ban- selinux module from template
include_role:
name: mwojtowicz.semodule
tasks_from: semodule.yml
vars:
selinux_module: "{{ main_selinux_modules }}"
loop_control:
loop_var: main_selinux_modules
loop:
- my-nginx
- my-f2bfsshd2
- my-grep
- my-reader3-6
- my-reader3-7
- my-reader0-3
- name: set SELinux nis_enable
seboolean:
name: nis_enabled
state: true
persistent: true
- name: set SELinux rsync_export_all_ro
seboolean:
name: rsync_export_all_ro
state: true
persistent: true
- name: Copy Automatic update config
copy:
src: files/dnf-automatic.conf
dest: /etc/dnf/automatic.conf
mode: '0644'
owner: root
group: root
- name: Ensure Automatic Updates are enabled
systemd:
name: dnf-automatic.timer
state: started
enabled: yes