-
Notifications
You must be signed in to change notification settings - Fork 21
/
build-nagios.yml
102 lines (81 loc) · 3.6 KB
/
build-nagios.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
---
- name: GET Nagios
get_url: url={{ nagiosurl }} dest={{ download_dir }}/{{ nagiossrc }}.tar.gz
- name: Unpack Nagios source files
shell: cd {{ download_dir }} && tar -xzvf {{ nagiossrc }}.tar.gz creates={{ download_dir }}/{{ nagiossrc }}
- name: Set upgrade as not required by default
set_fact:
nagios_upgrade_required: false
# https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/upgrading.html
- name: check if nagios main.php exists
stat: path=/usr/local/nagios/share/main.php
register: nagios_mainphp_file
- block:
- name: read nagios installed version
shell: head /usr/local/nagios/share/main.php | grep "this_version" | cut -d"=" -f 2 | tr --delete ";" | tr --delete "'" | xargs echo -n
changed_when: false
register: cmd_nagios_version
tags:
- skip_ansible_lint
check_mode: no
- name: Check if upgrade is required
set_fact:
nagios_upgrade_required: true
when: cmd_nagios_version.stdout != nagios_version
when: nagios_mainphp_file.stat.exists
- name: backup files before clean
copy:
src: "{{ item }}"
dest: "{{ item }}.bkp"
force: yes
with_items:
- "/usr/local/nagios/share/main.html"
- "/usr/local/nagios/share/index.html"
- "/usr/local/nagios/share/side.html"
- "{{ with_httpd_conf }}/nagios.conf"
- "/usr/local/nagios/bin/nagios"
- "/usr/local/nagios/include/nagios/nagios.h"
- "/etc/init.d/nagios"
when: nagios_upgrade_required
failed_when: false
- name: Clean files before upgrade
file:
path: "{{ item }}"
state: absent
with_items:
- "/usr/local/nagios/share/main.html"
- "/usr/local/nagios/share/index.html"
- "/usr/local/nagios/share/side.html"
- "{{ with_httpd_conf }}/nagios.conf"
- "/usr/local/nagios/bin/nagios"
- "/usr/local/nagios/var/rw"
- "/usr/local/nagios/include/nagios/nagios.h"
- "/etc/init.d/nagios"
when: nagios_upgrade_required
notify: restart nagios
- name: ./configure
shell: cd {{ download_dir }}/{{ nagiossrc }} && ./configure --with-command-group={{ monitoring_command_group }} -with-httpd_conf={{ with_httpd_conf }} --with-nagios-user={{ monitoring_user }} creates={{ download_dir }}/{{ nagiossrc }}/Makefile
- name: Make all
shell: cd {{ download_dir }}/{{ nagiossrc }} && make all creates={{ download_dir }}/{{ nagiossrc }}/base/nagios
- name: Make install
shell: cd {{ download_dir }}/{{ nagiossrc }} && make install creates=/usr/local/nagios/bin/nagios
- name: Make install-config
shell: cd {{ download_dir }}/{{ nagiossrc }} && make install-config creates=/usr/local/nagios/etc/nagios.cfg
- name: Make install-commandmode
shell: cd {{ download_dir }}/{{ nagiossrc }} && make install-commandmode creates=/usr/local/nagios/var/rw
- name: Make install-devel
shell: cd {{ download_dir }}/{{ nagiossrc }} && make install-devel creates=/usr/local/nagios/include/nagios/nagios.h
- name: Make install-webconf
shell: cd {{ download_dir }}/{{ nagiossrc }} && make install-webconf creates={{ with_httpd_conf }}/nagios.conf
notify: restart apache
- name: Make install-init
shell: cd {{ download_dir }}/{{ nagiossrc }} && make install-init creates=/etc/init.d/nagios
- name: Set htpasswd for gui users
htpasswd: path=/usr/local/nagios/etc/htpasswd.users name={{ item.user }} password={{ item.pass }} state=present
with_items: "{{ nagios_users }}"
- name: Workaround since service module fails for this version of nagios
raw: service nagios start
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '7'
changed_when: False
- name: Ensure Nagios is started
service: name=nagios state=started enabled=yes