Restart `xymon` service if configuration change

This commit is contained in:
Jeremy Gardais 2018-03-02 14:21:59 +01:00
parent 052c2fd7fe
commit b5fa9a5d67
5 changed files with 24 additions and 2 deletions

View File

@ -4,4 +4,5 @@
### Features ### Features
* Install `xymon` packages for Debian based distros. * Install `xymon` packages for Debian based distros.
* Manage `xymon` server configuration (/etc). * Manage `xymon` server configuration (/etc).
* Ensure to restart `xymon` server service if configuration changed.
* Ensure `xymon` server service is enabled and started. * Ensure `xymon` server service is enabled and started.

View File

@ -18,6 +18,7 @@ Manage Xymon server installation and configuration.
* **xymon_server__deploy_state**: The desired state this role should achieve [default: `present`]. * **xymon_server__deploy_state**: The desired state this role should achieve [default: `present`].
* **ymon_server__etc_src**: Directory used as source to templating /etc configuration content [default: `etc/xymon`]. * **ymon_server__etc_src**: Directory used as source to templating /etc configuration content [default: `etc/xymon`].
* **xymon_server__service_manage**: If the Xymon server service should be managed [default: `True`]. * **xymon_server__service_manage**: If the Xymon server service should be managed [default: `True`].
* **xymon_server__service_name**: The service name to manage [default: `xymon`].
## Example Playbook ## Example Playbook
@ -35,6 +36,7 @@ This role will:
* Install needed packages to provide `xymon` server. * Install needed packages to provide `xymon` server.
* Manage `xymon` server configuration (/etc). * Manage `xymon` server configuration (/etc).
* Ensure `xymon` server service is enabled and started. * Ensure `xymon` server service is enabled and started.
* Ensure to restart `xymon` server service if configuration changed.
## Development ## Development

View File

@ -27,6 +27,13 @@ xymon_server__base_packages:
# #
xymon_server__deploy_state: 'present' xymon_server__deploy_state: 'present'
# ]]]
# .. envvar:: xymon_server__service_name [[[
#
# The service name to manage.
#
xymon_server__service_name: 'xymon'
# ]]] # ]]]
# .. envvar:: xymon_server__service_manage [[[ # .. envvar:: xymon_server__service_manage [[[
# #

10
handlers/main.yml Normal file
View File

@ -0,0 +1,10 @@
---
# handlers file for xymon_server
- name: restart xymon server service
service:
name: '{{ xymon_server__service_name }}'
state: '{{ "restarted" if (xymon_server__deploy_state == "present" and
(xymon_server__service_manage | d(True) | bool))
else "stopped" }}'
enabled: '{{ xymon_server__service_manage | d(True) | bool }}'

View File

@ -21,6 +21,7 @@
state: directory state: directory
with_filetree: '{{ xymon_server__etc_src }}' with_filetree: '{{ xymon_server__etc_src }}'
when: item.state == 'directory' when: item.state == 'directory'
notify: ['restart xymon server service']
- name: Ensure /etc files are populated from templates - name: Ensure /etc files are populated from templates
template: template:
@ -28,12 +29,13 @@
dest: "/etc/xymon/{{ item.path | replace('.j2','') }}" dest: "/etc/xymon/{{ item.path | replace('.j2','') }}"
with_filetree: '{{ xymon_server__etc_src }}' with_filetree: '{{ xymon_server__etc_src }}'
when: item.state == 'file' when: item.state == 'file'
notify: ['restart xymon server service']
# Manage services [[[1 # Manage service [[[1
- name: Manage Xymon server service - name: Manage Xymon server service
service: service:
name: 'xymon' name: '{{ xymon_server__service_name }}'
state: '{{ "started" if (xymon_server__deploy_state == "present" and state: '{{ "started" if (xymon_server__deploy_state == "present" and
(xymon_server__service_manage | d(True) | bool)) (xymon_server__service_manage | d(True) | bool))
else "stopped" }}' else "stopped" }}'