From f430743161086be55da7a3c287540e3fbfb098b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Thu, 26 Jul 2018 18:09:35 +0200 Subject: [PATCH] Ensure Netdata service is enabled and started --- CHANGELOG.md | 1 + README.md | 3 +++ defaults/main.yml | 20 ++++++++++++++++++++ handlers/main.yml | 10 ++++++++++ tasks/main.yml | 3 +++ 5 files changed, 37 insertions(+) create mode 100644 handlers/main.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 09b406a..47f033e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,3 +5,4 @@ * Install Netdata. * Can choose to install recommends packages. * Manage Netdata configuration (/etc). +* Ensure Netdata service is enabled and started. diff --git a/README.md b/README.md index b424230..78ddbc7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml index 898b59a..3500c12 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 [[[ # ----------------------------- diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..8e15e70 --- /dev/null +++ b/handlers/main.yml @@ -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 }}' diff --git a/tasks/main.yml b/tasks/main.yml index 8673422..e0e4be9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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']