Ensure Netdata service is enabled and started

This commit is contained in:
Jeremy Gardais 2018-07-26 18:09:35 +02:00
parent 9fc3a461ce
commit f430743161
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
5 changed files with 37 additions and 0 deletions

View File

@ -5,3 +5,4 @@
* Install Netdata.
* Can choose to install recommends packages.
* Manage Netdata configuration (/etc).
* Ensure Netdata service is enabled and started.

View File

@ -18,6 +18,8 @@ A role to manage Netdata installation and configuration.
* **netdata__install_recommends**: If recommends packages should be install [default: `True`].
* **netdata__deploy_state**: The desired state this role should achieve. [default: `present`].
* **netdata__etc_src**: Directory used as source to templating /etc/netdata configuration content [default: `../templates/etc/netdata`].
* **netdata__service_name**: The service name to manage [default: `netdata`].
* **netdata__service_manage**: If the Netdata services should be managed [default: `True`].
## Example Playbook
@ -60,6 +62,7 @@ mynode.DOMAIN
This role will:
* Install needed packages to provide `netdata` service.
* Manage Netdata configuration (/etc/netdata).
* Ensure Netdata service is enabled and started.
## Development

View File

@ -36,6 +36,26 @@ netdata__install_recommends: True
#
netdata__deploy_state: 'present'
# ]]]
# .. envvar:: netdata__service_name [[[
#
# The service name to manage.
#
netdata__service_name: 'netdata'
# ]]]
# .. envvar:: netdata__service_manage [[[
#
# If the Netdata service should be managed? Possible options:
#
# ``True``
# Default. The service is started and enabled.
#
# ``False``
# The service is disabled from startup.
#
netdata__service_manage: True
# ]]]
# ]]]
# Configuration [[[
# -----------------------------

10
handlers/main.yml Normal file
View File

@ -0,0 +1,10 @@
---
# handlers file for netdata
- name: Restart Netdata service
service:
name: '{{ netdata__service_name }}'
state: '{{ "restarted" if (netdata__deploy_state | bool and
netdata__service_manage | bool) else "stopped" }}'
enabled: '{{ netdata__service_manage | bool }}'
#state: '{{ "restarted" if (netdata__deploy_state | bool and
#netdata__service_manage | bool) else omit }}'

View File

@ -23,6 +23,7 @@
mode: '0755'
with_filetree: '{{ netdata__etc_src }}'
when: item.state == 'directory'
notify: ['Restart Netdata service']
- name: Generate Netdata configuration files
template:
@ -33,6 +34,7 @@
mode: '{{ item.mode }}'
with_filetree: '{{ netdata__etc_src }}'
when: item.state == 'file'
notify: ['Restart Netdata service']
- name: Generate Netdata configuration symlinks
template:
@ -42,3 +44,4 @@
force: true
with_filetree: '{{ netdata__etc_src }}'
when: item.state == 'link'
notify: ['Restart Netdata service']