forked from networklore/ansible-role-nagios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-nagios.yml
126 lines (108 loc) · 3.58 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
- name: GET Nagios
get_url:
url: "{{ nagios_url }}"
dest: "{{ nagios_download_dir }}/{{ nagios_src }}.tar.gz"
- name: Unpack Nagios source files
unarchive:
src: "{{ nagios_download_dir }}/{{ nagios_src }}.tar.gz"
dest: "{{ nagios_download_dir }}"
remote_src: true
- 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: false
- 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: true
with_items:
- "/usr/local/nagios/share/main.php"
- "/usr/local/nagios/share/index.php"
- "/usr/local/nagios/share/side.php"
- "{{ nagios_httpd_location }}/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.php"
- "/usr/local/nagios/share/index.php"
- "/usr/local/nagios/share/side.php"
- "{{ nagios_httpd_location }}/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 Nagios
command: ./configure --with-command-group={{ nagios_monitoring_command_group }} --with-nagios-user={{ nagios_monitoring_user }}
args:
chdir: "{{ nagios_download_dir }}/{{ nagios_src }}"
creates: "{{ nagios_download_dir }}/{{ nagios_src }}/Makefile"
- name: Make all
command: make all
args:
chdir: "{{ nagios_download_dir }}/{{ nagios_src }}"
creates: "{{ nagios_download_dir }}/{{ nagios_src }}/base/nagios"
- name: Make install
command: make install
args:
chdir: "{{ nagios_download_dir }}/{{ nagios_src }}"
creates: /usr/local/nagios/bin/nagios
- name: Make install-config
command: make install-config
args:
chdir: "{{ nagios_download_dir }}/{{ nagios_src }}"
creates: /usr/local/nagios/etc/nagios.cfg
- name: Make install-init
command: make install-init
args:
chdir: "{{ nagios_download_dir }}/{{ nagios_src }}"
creates: "{{ nagios_init }}"
notify: restart nagios
- name: Make install-commandmode
command: make install-commandmode
args:
chdir: "{{ nagios_download_dir }}/{{ nagios_src }}"
creates: /usr/local/nagios/var/rw
notify: restart nagios
- name: Make install-config
command: make install-config
args:
chdir: "{{ nagios_download_dir }}/{{ nagios_src }}"
creates: /usr/local/nagios/etc/nagios.cfg
- name: Make install-webconf
command: make install-webconf
args:
chdir: "{{ nagios_download_dir }}/{{ nagios_src }}"
creates: "{{ nagios_httpd_location }}/nagios.conf"
notify: restart apache
- name: Ensure Nagios is enabled on boot
service:
name: nagios
enabled: true