/
icinga.yml
122 lines (102 loc) · 3.91 KB
/
icinga.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
---
- hosts: icinga
vars:
selinux_policy_drop_dir: /tmp/selinux_ansible_drop
tasks:
#############################################
- name: check for pkg repository
stat: path=/etc/yum.repos.d/ICINGA-release.repo
register: yumrepo
#############################################
- name: add pkg repository if missing
get_url: url=http://packages.icinga.org/epel/ICINGA-release.repo \
dest=/etc/yum.repos.d/ICINGA-release.repo
when: yumrepo.stat.exists == false
#############################################
- name: mysql packages
yum: name={{ item }} state=latest
with_items:
- mariadb
- mariadb-server
- MySQL-python
#############################################
- name: icinga packages
yum: name={{ item }} state=latest
with_items:
- icinga2
- nagios-plugins-all
- icinga2-ido-mysql
- icingaweb2
- icingacli
#############################################
- name: icinga db
mysql_db: name=icinga state=present
login_user=root login_password={{ mysql_root_password }}
notify: create-icinga-db
#############################################
- name: icinga user
mysql_user: name=icinga state=present password={{ icinga_db_password }}
append_privs=yes
login_user=root login_password={{ mysql_root_password }}
priv='icinga.*:SELECT,INSERT,UPDATE,DELETE,DROP,CREATE VIEW,INDEX,EXECUTE'
#############################################
- name: store MySQL login parms for icinga
lineinfile:
dest=/etc/icinga2/features-available/ido-mysql.conf
regexp='^\s*password\s*=\s*"'
line=' password = "{{ icinga_db_password }}"'
insertafter="^.*IdoMysqlConnection.*{"
# '
notify: reload-icinga
#############################################
- name: PHP default timezone
lineinfile: dest=/etc/php.ini regexp="^\s*date.timezone=" line="date.timezone=America/New_York" insertafter="^;date.timezone"
#############################################
- name: Turn off SELinux for httpd - icingaweb2 cant hack it
command: semanage permissive -a httpd_t
#############################################
- name: copy http root index file
copy: dest=/var/www/html/index.html src=index.html force=no
#############################################
- name: insert icinga link in http index file
lineinfile:
dest=/var/www/html/index.html
regexp="/icingaweb2/"
line="<li><a href="/icingaweb2/">Icinga Monitoring</a></li>"
insertafter="<ul>"
#############################################
- name: enable services
service: name={{ item }} enabled=yes state=started
with_items:
- httpd
- mariadb
- icinga2
#############################################
- name: Gather icinga2 enabled features
command: icinga2 feature list
register: icinga2feat
#############################################
- name: Enable ido-mysql feature
command: icinga2 feature enable command
when: "{{ icinga2feat.stdout | search('Disabled features:.* ido-mysql.*\n') }}"
notify: restart-icinga
#############################################
- name: Enable command feature
command: icinga2 feature enable command
when: "{{ icinga2feat.stdout | search('Disabled features:.* command.*\n') }}"
notify: restart-icinga
#############################################
handlers:
- name: create-icinga-db
mysql_db: name=icinga
login_password={{ mysql_root_password }} login_user=root
state=import target=/usr/share/icinga2-ido-mysql/schema/mysql.sql
#############################################
- name: restart-icinga
service: name=icinga2 state=restarted
#############################################
- name: reload-icinga
service: name=icinga2 state=reloaded
#############################################
- name: reload-httpd
service: name=httpd state=reloaded