summaryrefslogtreecommitdiffstats
path: root/roles/base/tasks/main.yml
blob: 0a2ff3a0d33cb3eaae0188c4f0f5e1a2c82eec77 (plain)
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
---

#
# This is the base role for all machines.
# Things in here are things we want to do to every machine no matter what.
#

- name: ensure packages required for semanage are installed (yum)
  yum: name={{ item }} state=present
  when: ansible_distribution_major_version|int < 22
  with_items:
  - policycoreutils-python
  tags:
  - selinux

- name: ensure packages required for semanage are installed (dnf)
  dnf: name={{ item }} state=present
  when: ansible_distribution_major_version|int > 21 and ansible_cmdline.ostree is not defined
  with_items:
  - policycoreutils-python-utils
  tags:
  - selinux

# XXX fixme # a datacenter 'fact' from setup
- name: /etc/resolv.conf
  copy: src={{ item }} dest=/etc/resolv.conf
  with_first_found:
  - "{{ resolvconf }}"
  - resolv.conf/{{ inventory_hostname }}
  - resolv.conf/{{ host_group }}
  - resolv.conf/{{ datacenter }}
  - resolv.conf/resolv.conf
  tags:
  - config
  - resolvconf
  - base
  - ifcfg

- name: check for NetworkManager/nmcli
  command: /usr/bin/test -f /usr/bin/nmcli
  register: nmclitest
  ignore_errors: true
  changed_when: false
  failed_when: "1 != 1"
  check_mode: no
  tags:
   - config
   - resolvconf
   - base
   - ifcfg

- name: disable resolv.conf control from NM
  ini_file: dest=/etc/NetworkManager/NetworkManager.conf section=main option=dns value=none
  notify:
  - restart NetworkManager
  when: ansible_distribution_major_version|int >=7 and nmclitest|success and ( not ansible_ifcfg_blacklist)
  tags:
   - config
   - resolvconf
   - base
   - ifcfg

- name: get interface uuid
  shell: nmcli -f "DEVICE,UUID" c show --active | grep -E '^eth|^br'
  register: if_uuid
  changed_when: false
  failed_when: 'if_uuid.stdout == ""'
  check_mode: no
  when: ansible_distribution_major_version|int >=7 and nmclitest|success and ( not ansible_ifcfg_blacklist )
  tags:
   - config
   - ifcfg
   - base

- name: copy ifcfg files - non virthost
  template: src=ifcfg.j2 dest=/etc/sysconfig/network-scripts/ifcfg-{{item}} mode=0644
  with_items:
  - "{{ ansible_interfaces }}"
  notify:
#  - restart NetworkManager
  - reload NetworkManager-connections
  - apply interface-changes
  when: (virthost is not defined) and (item.startswith(('eth','br'))) and (hostvars[inventory_hostname]['ansible_' + item.replace('-','_')]['type'] == 'ether') and (ansible_distribution_major_version|int >=7) and hostvars[inventory_hostname]['ansible_' + item.replace('-','_')]['active'] and nmclitest|success and ( not ansible_ifcfg_blacklist ) and ( ansible_ifcfg_whitelist is not defined or item in ansible_ifcfg_whitelist )
  tags:
   - config
   - ifcfg
   - base

- name: global default packages to install (yum)
  yum: state=present name={{ item }}
  with_items:
   - "{{ global_pkgs_inst }}"
  tags:
  - packages
  - base
  when: ansible_distribution_major_version|int < 22

- name: global default packages to install (dnf)
  dnf: state=present name={{ item }}
  with_items:
   - "{{ global_pkgs_inst }}"
  tags:
  - packages
  - base
  when: ansible_distribution_major_version|int > 21 and ansible_cmdline.ostree is not defined

- name: make sure hostname is set right on rhel7 hosts
  hostname: name="{{inventory_hostname}}"

- name: check if sshd port is already known by selinux
  shell: semanage port -l | grep ssh
  register: sshd_selinux_port
  check_mode: no
  changed_when: false
  tags:
  - sshd_config
  - config
  - sshd
  - selinux
  - base

- name: allow alternate sshd port
  command: semanage port -a -t ssh_port_t -p tcp {{ sshd_port }}
  when: sshd_selinux_port.stdout.find('{{ sshd_port }}') == -1
  tags:
  - sshd_config
  - config
  - sshd
  - selinux
  - base

- name: Set up SSH certificates
  include: sshcerts.yml

- name: sshd_config
  copy: src={{ item }} dest=/etc/ssh/sshd_config mode=0600
  with_first_found:
    - "{{ sshd_config }}"
    - ssh/sshd_config.{{ inventory_hostname }}
    - ssh/sshd_config.{{ host_group }}
    - ssh/sshd_config.{{ dist_tag }}
    - ssh/sshd_config.{{ ansible_distribution }}
    - ssh/sshd_config.{{ ansible_distribution_version }}
    - ssh/sshd_config.default
  notify:
  - restart sshd
  tags:
  - sshd_config
  - config
  - sshd
  - base

- name: set root passwd
  user: name=root password={{ rootpw }} state=present
  tags:
  - rootpw
  - base
  when: not (inventory_hostname.startswith('rawhide') or inventory_hostname.startswith('branched') or inventory_hostname.startswith('compose') or inventory_hostname.startswith('build') or inventory_hostname.startswith('arm') or inventory_hostname.startswith('bkernel') or inventory_hostname.startswith('koji01.stg') or inventory_hostname.startswith('aarch64') or inventory_hostname.startswith('s390') or inventory_hostname.startswith('fed-cloud09') or inventory_hostname.startswith('ppc8-04'))

- name: add ansible root key
  authorized_key: user=root key="{{ item }}"
  with_file:
  - ansible-pub-key
  tags:
  - config
  - base

- name: make sure our resolv.conf is the one being used - set RESOLV_MODS=no in /etc/sysconfig/network
  lineinfile: dest=/etc/sysconfig/network create=yes backup=yes state=present line='RESOLV_MODS=no' regexp=^RESOLV_MODS=
  tags:
  - config
  - base

- name: dist pkgs to remove (yum)
  yum: state=absent name={{ item }}
  with_items:
   - "{{ base_pkgs_erase }}"
  tags:
  - packages
  - base
  when: ansible_distribution_major_version|int < 22

- name: dist pkgs to install (yum)
  yum: state=present name={{ item }}
  with_items:
   - "{{ base_pkgs_inst }}"
  tags:
  - packages
  - base
  when: ansible_distribution_major_version|int < 22

- name: dist pkgs to remove (dnf)
  dnf: state=absent name={{ item }}
  with_items:
   - "{{ base_pkgs_erase }}"
  tags:
  - packages
  - base
  when: ansible_distribution_major_version|int > 21 and ansible_cmdline.ostree is not defined

- name: dist pkgs to install (dnf)
  dnf: state=present name={{ item }}
  with_items:
   - "{{ base_pkgs_inst }}"
  tags:
  - packages
  - base
  when: ansible_distribution_major_version|int > 21 and ansible_cmdline.ostree is not defined

- name: dist disabled services
  service: state=stopped enabled=false name={{ item }}
  with_items:
   - "{{ service_disabled }}"
  tags:
  - service
  - config
  - base

- name: dist enabled services
  service: state=started enabled=true name={{ item }}
  with_items:
   - "{{ service_enabled }}"
  tags:
  - service
  - config
  - base

- name: iptables
  template: src={{ item }} dest=/etc/sysconfig/iptables mode=0600 validate="/sbin/iptables-restore --text %s"
  with_first_found:
   - iptables/iptables.{{ datacenter }}
   - iptables/iptables.{{ inventory_hostname }}
   - iptables/iptables.{{ host_group }}
   - iptables/iptables.{{ env }}
   - iptables/iptables
  when: not inventory_hostname.startswith(('fed-cloud','osbs'))
  notify:
  - restart iptables
  - reload libvirtd
  tags:
  - iptables
  - config
  - base

- name: iptables service enabled
  service: name=iptables state=started enabled=true
  tags:
  - iptables
  - service
  - base

- name: ip6tables
  template: src={{ item }} dest=/etc/sysconfig/ip6tables mode=0600 backup=yes
  with_first_found:
   - iptables/ip6tables.{{ datacenter }}
   - iptables/ip6tables.{{ inventory_hostname }}
   - iptables/ip6tables.{{ host_group }}
   - iptables/ip6tables.{{ env }}
   - iptables/ip6tables
  when: not inventory_hostname.startswith('fed-cloud09')
  notify:
  - restart ip6tables
  - reload libvirtd
  tags:
  - ip6tables
  - config
  - base

- name: ip6tables service enabled
  service: name=ip6tables state=started enabled=true
  tags:
  - ip6tables
  - service
  - base

- name: enable journald persistence
  file: path=/var/log/journal state=directory
        owner=root group=systemd-journal mode=2755
  when: ansible_distribution_major_version|int >= 7
  tags:
  - journald
  - config
  - base
  notify:
  - flush journald tmpfiles to persistent store

- name: rsyslog.conf
  copy: src={{ item }} dest=/etc/rsyslog.conf mode=0644
  with_first_found:
    - rsyslog/rsyslog.conf.{{ inventory_hostname }}
    - rsyslog/rsyslog.conf.{{ dist_tag }}
    - rsyslog/rsyslog.conf.default
  notify:
  - restart rsyslog
  tags:
  - rsyslogd
  - config
  - base

- name: rsyslog log rotate for rsyslog servers
  copy: src=rsyslog/merged-rsyslog dest=/etc/logrotate.d/merged-rsyslog mode=0644
  when: inventory_hostname.startswith('log')
  notify:
  - restart rsyslog
  tags:
  - rsyslogd
  - config
  - base

- name: add rsyslog config to /etc/rsyslog.d
  copy: src={{ item }} dest=/etc/rsyslog.d/ owner=root group=root mode=0644
  with_fileglob:
   - rsyslog/*.conf
  notify:
  - restart rsyslog
  tags:
  - rsyslogd
  - config
  - base

- name: log everything to log01 except on mirrorlist, do not log local4 there.
  copy: src=rsyslog/rsyslog-log01 dest=/etc/rsyslog.d/rsyslog-log01.conf mode=0644
  when: not inventory_hostname.startswith(('mirrorlist','copr','jenkins'))
  tags:
  - rsyslogd
  - config
  - base

- name: log everything to log01 except on mirrorlist, do log local4 there.
  copy: src=rsyslog/rsyslog-log01-nolocal4 dest=/etc/rsyslog.d/rsyslog-log01.conf mode=0644
  when: inventory_hostname.startswith('mirrorlist')
  tags:
  - rsyslogd
  - config
  - base

- name: rsyslogd make systemd limits directory for file handles
  file: dest=/etc/systemd/system/rsyslog.service.d/ mode=0755 owner=root group=root state=directory
  when: inventory_hostname.startswith('log')
  tags:
  - rsyslogd
  - config

- name: rsyslogd put systemd limits directory for file handles
  copy: src=rsyslog/rsyslog-limits.conf dest=/etc/systemd/system/rsyslog.service.d/limits.conf mode=0644
  when: inventory_hostname.startswith('log')
  tags:
  - rsyslogd
  - config

- name: Setup postfix
  include: postfix.yml

#
# This task installs some common scripts to /usr/local/bin
# scripts are under roles/base/files/common-scripts
#

- name: Install common scripts
  copy: src={{ item }} dest=/usr/local/bin/ owner=root group=root mode=0755
  with_fileglob:
   - common-scripts/*
  tags:
  - config
  - base
  - common-scripts

- name: install a sync httpd logs cron script only on log01
  copy: src=syncHttpLogs.sh dest=/etc/cron.daily/syncHttpLogs.sh mode=0755
  when: inventory_hostname.startswith('log01')
  tags:
  - config
  - base

- name: Drop in a little system_identification note
  template: src=system_identification dest=/etc/system_identification
  tags:
  - config
  - base

#
# Blacklist the cdc_ether module as we don't want it loading mgmt usb0 and spewing to logs.
#
- name: Blacklist cdc_ether module
  copy: src=blacklist-cdc_ether.conf dest=/etc/modprobe.d/blacklist-cdc_ether.conf
  when: ansible_virtualization_role == 'host'
  tags:
  - config
  - base
  - cdc_ether

#
# Watchdog stuff
#
- name: Set up watchdog
  include: watchdog.yml


#Set PS1 to show stage environment at PS1
#
- name: set PS1 for stage in /etc/profile.d
  copy: >
    src=setstgps1.sh
    dest="/etc/profile.d/setstgps1.sh"
    owner=root
    group=root
    mode=0644
  when: env == 'staging'
  tags:
  - base
  - config
  - prompt

#Set PS1 to show prod environment at PS1
#
- name: set PS1 for prod in /etc/profile.d
  copy: >
    src=setprodps1.sh
    dest="/etc/profile.d/setprodps1.sh"
    owner=root
    group=root
    mode=0644
  when: env == 'production'
  tags:
  - base
  - config
  - prompt

# Set krb5 conf
- name: configure krb5
  template: src=krb5.conf.j2 dest=/etc/krb5.conf owner=root group=root mode=0644
  when: not inventory_hostname.startswith('ipa')
  tags:
  - base
  - config
  - krb5

- name: configure krb5 (IPA master)
  template: src=krb5.conf.master.j2 dest=/etc/krb5.conf owner=root group=root mode=0644
  when: inventory_hostname.startswith('ipa')
  tags:
  - base
  - config
  - krb5

- name: Setup host keytab
  include: keytab.yml