-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.yml
More file actions
408 lines (364 loc) · 9.24 KB
/
Copy pathmain.yml
File metadata and controls
408 lines (364 loc) · 9.24 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
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
402
403
404
405
406
407
408
- name: Ensuring ansible can create local facts
ansible.builtin.file:
path: /etc/ansible/facts.d
state: directory
- name: Creating folder to drop enabled repositories
ansible.builtin.file:
path: /etc/centos.repos.d
state: directory
- name: Ensuring we have a place to store centos infra scripts
ansible.builtin.file:
path: /usr/libexec/centos
state: directory
- name: Adding admin group
ansible.builtin.group:
name: admins
state: present
- name: Adding admin user[s]
user:
name: "{{ item.login_name }}"
state: present
comment: "{{ item.full_name }}"
shell: /bin/bash
append: yes
groups: admins
with_items: "{{ admins_list }}"
when: admins_list is defined
loop_control:
label: "{{ item.login_name }}"
tags:
- users
- name: Importing admin user[s] ssh pub keys
authorized_key:
user: "{{ item.0.login_name }}"
key: "{{ item.1 }}"
with_subelements:
- "{{ admins_list }}"
- ssh_pub_key
when: admins_list is defined
loop_control:
label: "{{ item.0.login_name }}"
tags:
- users
- name: Giving sudo access for admin users when needed
template:
src: templates/sudofile.j2
dest: /etc/sudoers.d/{{ item.login_name }}
mode: 0440
owner: root
group: root
with_items: "{{ admins_list }}"
loop_control:
label: "{{ item.login_name }}"
when: admins_list is defined and item.sudo_right
tags:
- users
- name: Modifying /etc/hosts if defined/needed (special case)
ansible.builtin.blockinfile:
path: /etc/hosts
block: "{{ etc_hosts_block }}"
when:
- etc_hosts_block is defined
tags:
- hosts
- name: Configuring dnf/yum proxy settings if needed
ansible.builtin.lineinfile:
path: /etc/yum.conf
state: present
regexp: '^proxy='
line: proxy={{ dnf_proxy_url }}
when:
- dnf_use_proxy is defined
- dnf_use_proxy
tags:
dnf_proxy
- include_tasks: rhel.yml
when: ansible_distribution == 'RedHat'
tags:
- rhel
- name: Ensuring CRB is enabled on CentOS Stream hosts
shell:
cmd: dnf repolist|grep -q crb || (dnf config-manager --set-enabled crb ; exit 2)
register: crb
changed_when: crb.rc == 2
failed_when: crb.rc == 1
when:
- ansible_distribution == 'CentOS'
tags:
- repo
- block:
- name: Adding CentOS Infra key
copy:
src: files/RPM-GPG-KEY-CentOS-Infra
dest: /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Infra
- name: Configuring CentOS Infra admin repo
template:
src: centos-admin.repo.j2
dest: /etc/yum.repos.d/centos-admin.repo
mode: 0644
tags:
- yum
when: centos_infra_repo
- name: Creating selinux custom policy drop folder
file:
path: /etc/selinux/centos
state: directory
owner: root
group: root
mode: 0750
- name: Ensuring some default packages are installed
yum:
name: "{{ packages_list }}"
state: installed
- name: Customizing motd
template:
src: motd.j2
dest: /etc/motd
owner: root
group: root
mode: 0644
tags:
- motd
when: customized_motd
- name: Ensuring some el snippet aren't shown on login
file:
state: absent
path: "/etc/motd.d/{{ item }}"
loop:
- cockpit
- insights-client
tags:
- motd
- name: Displaying colored hostname in shell
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "/etc/sysconfig/{{ item }}"
mode: 0755
owner: root
group: root
with_items:
- bash-prompt-default
- bash-prompt-xterm
tags:
- motd
- prompt
when: customized_motd
- name: Ensuring tuned is installed
ansible.builtin.yum:
name: tuned
state: installed
tags:
- tuned
- name: Ensuring tuned is started
ansible.builtin.service:
name: tuned
state: started
enabled: True
tags:
- tuned
- name: Ensuring correct tuned profile is configured
ansible.builtin.template:
src: tuned_active_profile.j2
dest: /etc/tuned/active_profile
mode: 0644
register: tuned_setting_7
when: ansible_distribution_major_version == "7"
tags:
- tuned
- name: Ensuring correct tuned profile is configured (el6 version)
ansible.builtin.template:
src: tuned_active_profile.j2
dest: /etc/tune-profiles/active_profile
mode: 0644
register: tuned_setting_6
when: ansible_distribution_major_version == "6"
tags:
- tuned
- name: Reloading tuned profile if needed
shell: "tuned-adm profile {{ tuned_profile }}"
when: tuned_setting_6 is changed or tuned_setting_7 is changed
tags:
- tuned
- ansible.builtin.import_role:
name: iptables
tags:
- iptables
- ansible.builtin.import_role:
name: zabbix-agent
when: zabbix_monitoring
tags:
- monitoring
- ansible.builtin.import_role:
name: sshd
tags:
- sshd
- users
- name: Adding additional users
user:
name: "{{ item.login_name }}"
state: present
comment: "{{ item.full_name }}"
shell: "{{ item.shell | default('/bin/bash') }}"
with_items: "{{ local_users_list }}"
loop_control:
label: "{{ item.login_name }}"
when: local_users_list is defined
tags:
- users
- name: Importing local users ssh pub keys
authorized_key:
user: "{{ item.0.login_name }}"
key: "{{ item.1 }}"
with_subelements:
- "{{ local_users_list }}"
- ssh_pub_key
loop_control:
label: "{{ item.0.login_name }}"
when: local_users_list is defined
tags:
- users
- name: Giving sudo access when needed
template:
src: templates/sudofile.j2
dest: "/etc/sudoers.d/{{ item.login_name }}"
mode: 0440
owner: root
group: root
with_items: "{{ local_users_list }}"
when:
- local_users_list is defined
- item.sudo_right
loop_control:
label: "{{ item.login_name }}"
tags:
- users
- name: Removing expired accounts
ansible.builtin.user:
name: "{{ item }}"
state: absent
remove: False
with_items: "{{ local_expired_users }}"
tags:
- users
- cleanup
- name: UTC everywhere
community.general.timezone:
name: UTC
tags:
- tz
- include_tasks: chrony.yml
tags:
- chrony
- time
- include_tasks: os_updates.yml
tags:
- yum
- dnf
- updates
- name: Importing TLS CA that we want to trust (if any)
copy:
src: "{{ pkistore }}/{{ item }}"
dest: "/etc/pki/ca-trust/source/anchors"
notify: update_ca_trust
with_items: "{{ pki_trusted_ca_list }}"
tags:
- pki
- name: Distributing specific files not coming from roles/templates
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ item.owner }}"
mode: "{{ item.mode }}"
with_items: "{{ baseline_distributed_files }}"
loop_control:
label: "{{ item.dest }}"
tags:
- distributed_files
- name: Enabling specific selinux booleans / per host level
ansible.posix.seboolean:
name: "{{ item }}"
state: yes
persistent: yes
with_items: "{{ local_selinux_booleans }}"
tags:
- selinux
- name: Enabling specific host/group cron jobs
ansible.builtin.cron:
name: "{{ item.name }}"
job: "{{ item.job }}"
user: "{{ item.user|default('root') }}"
hour: "{{ item.hour|default('*') }}"
day: "{{ item.day|default('*') }}"
minute: "{{ item.minute|default('*') }}"
with_items: "{{ local_cron_entries }}"
loop_control:
label: "{{ item.name }}"
tags:
- cron
- name: Updating crypto-policy if needed
ansible.builtin.shell:
cmd: "update-crypto-policies --show |grep -q {{ baseline_crypto_policy }} || (update-crypto-policies --set {{ baseline_crypto_policy }} >/dev/null 2>&1 ; echo changed)"
register: crypto_policy
changed_when: '"changed" in crypto_policy.stdout'
when:
- baseline_crypto_policy is defined
- ansible_distribution_major_version | int > 7
tags:
- crypto_policy
- name: Configuring NFS mount default options
ansible.builtin.lineinfile:
path: /etc/nfsmount.conf
state: present
line: Sec=sys
- block:
- name: Ensuring addtional volume[s] is/are defined
ansible.posix.mount:
src: "{{ item.src }}"
path: "{{ item.dest }}"
fstype: nfs
state: present
opts: "{{ item.opts | default('defaults') }}"
register: mountpoints
with_items: "{{ nfs_mountpoints }}"
loop_control:
label: "{{ item.dest }}"
tags:
- nfs
- name: Ensuring addtional volume[s] is/are mounted
ansible.posix.mount:
src: "{{ item.item.src }}"
path: "{{ item.item.dest }}"
fstype: nfs
state: mounted
opts: "{{ item.opts | default('defaults') }}"
with_items: "{{ mountpoints.results }}"
when: item.changed
loop_control:
label: "{{ item.item.dest }}"
tags:
- nfs
- name: Kernel/sysctl parameters
ansible.posix.sysctl:
name: "{{ item.name }}"
value: "{{ item.value }}"
state: present
sysctl_set: yes
reload: yes
with_items: "{{ sysctl_settings }}"
tags:
- sysctl
- name: Extra directories
file:
path: "{{ item.path }}"
state: directory
setype: "{{ item.secontext | default('_default') }}"
owner: "{{ item.owner | default('root') }}"
group: "{{ item.group | default('root') }}"
with_items: "{{ directories_list }}"
loop_control:
label: "{{ item.path }}"
tags:
- directories
- include_tasks: rssh-users.yml
tags:
- rssh