From 4ee9627f5682d35bef4b0fa422d4ba9880eb2ca8 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 27 Jun 2019 18:36:36 +0200 Subject: [PATCH] Immediately restart the nrpe service after a configuration change. --- library/roles/nagios/tasks/nagios.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/roles/nagios/tasks/nagios.yml b/library/roles/nagios/tasks/nagios.yml index ca1f7d8..32f82d5 100644 --- a/library/roles/nagios/tasks/nagios.yml +++ b/library/roles/nagios/tasks/nagios.yml @@ -33,19 +33,28 @@ - name: Install the global nrpe commands file template: src=common-nrpe.cfg.j2 dest=/etc/nagios/nrpe.d/common.cfg owner=root group=root mode=444 notify: Restart NRPE server + register: nrpe_restart tags: [ 'nagios', 'nrpe', 'nrpe_cfg' ] - name: set the NRPE ACL action: | lineinfile name=/etc/nagios/nrpe.cfg regexp="allowed_hosts=" line="allowed_hosts=127.0.0.1,{% for ip in nagios_monitoring_server_ip %}{{ ip }}{%if not loop.last %},{% endif %}{% endfor %}" notify: Reload NRPE server + register: nrpe_restart tags: [ 'nagios', 'nrpe', 'nrpe_cfg' ] - name: set the NRPE default timeout lineinfile: name=/etc/nagios/nrpe.cfg regexp="command_timeout=" line="command_timeout={{ nrpe_command_timeout }}" notify: Reload NRPE server + register: nrpe_restart tags: [ 'nagios', 'nrpe', 'nrpe_cfg' ] +- name: Restart NRPE server + service: name=nagios-nrpe-server state=restarted + when: + - nrpe_restart is defined + - nrpe_restart is changed + - name: nagios needs root to execute some commands. We do it via sudo template: src=nagios.sudoers.j2 dest=/etc/sudoers.d/nagios owner=root group=root mode=0440 tags: [ 'nagios', 'nrpe', 'sudo' ]