/
icinga-client-revert.yml
57 lines (57 loc) · 1.92 KB
/
icinga-client-revert.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
---
- name: Configure Icinga Master for Each New Client
hosts: icinga_master
become: yes
gather_facts: no
vars:
fqdn_attr: "fqdn"
tasks:
- name: "Remove host config for {{ hostvars[item][fqdn_attr] }}"
file:
dest: /etc/icinga2/hosts.d/{{ hostvars[item][fqdn_attr] }}.conf
state: absent
with_items: "{{ groups.new_icinga_clients }}"
- name: "Copy sql cleanup"
copy:
src: files/prepare-directory.sql
dest: /tmp/prepare-directory.sql
- shell: source /etc/icinga2/cloud/system_passwords;sed "s/{demo_client}/{{ hostvars[item][fqdn_attr] }}/g" /tmp/prepare-directory.sql | mysql -u root -p$ROOT_DB_PWD icinga
with_items: "{{ groups.new_icinga_clients }}"
- set_fact:
folder: /etc/icinga2/pki
- name: "Check icinga2 version"
shell: yum list installed icinga2 | tail -n1 | awk {'print $2'} | awk -F ".el7." {' print $1'}
register: icinga_ver
- set_fact:
folder: /var/lib/icinga2/certs
when: icinga_ver.stdout | version_compare('2.8', '>=')
- name: Configure Icinga 2 Client Machine
hosts: new_icinga_clients
strategy: free
become: yes
vars:
master_group: "icinga_master"
fqdn_attr: "fqdn"
pre_tasks:
- include_vars: vars/test-vars.yml
- set_fact:
cert_folder: "{{ hostvars[groups[master_group][0]]['folder'] }}"
master_fqdn: "{{ hostvars[groups[master_group][0]][fqdn_attr] }}"
- name: "Checking if previously run"
stat:
path: "{{ cert_folder }}/{{ master_fqdn }}.crt"
register: cert
- debug:
msg: "Icinga not previously configured for this client"
when: cert.stat.exists == false
roles:
- { role: icinga-client-revert, when: "cert.stat.exists == true" }
- name: Reload Icinga On Master
hosts: icinga_master
become: yes
gather_facts: no
tasks:
- name: Reload icinga daemon
service:
name: icinga2
state: reloaded