From ded78c8625586b67eb8ec3ec2fc5f568965345da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Mon, 6 Aug 2018 14:54:42 +0200 Subject: [PATCH] Combine 4 vars to generate Netdata configuration --- CHANGELOG.md | 1 + README.md | 47 ++++++++++++++------------- defaults/main.yml | 46 +++++++++++++++++++++++--- tasks/main.yml | 18 ++++++++-- templates/etc/netdata/netdata.conf.j2 | 1 + templates/etc/netdata/stream.conf.j2 | 1 + 6 files changed, 84 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bda51af..8eebf5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,3 +9,4 @@ * Manage IP address and port used. * Manage memory mode. * Define some vars to manage master and slaves configuration. +* Combine 4 vars to generate Netdata configuration. diff --git a/README.md b/README.md index 099e811..59ca59b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,11 @@ A role to manage Netdata installation and configuration. * **netdata__base_packages** : List of base packages in order to provide Netdata [default : `netdata`]. * **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__group_name** : Name of the directory which contains configuration files for this specific group [default : `nonexistent-host-group`]. +* **netdata__default_etc_src** : Directory which contains configuration files for Netdata from this role [default : `../templates/etc/netdata`]. +* **netdata__etc_src** : Directory which contains configuration files that should be managed on all hosts [default : `../templates/etc/netdata`]. +* **netdata__group_etc_src** : Directory which contains configuration files for Netdata that should be managed by a specific Ansible inventory group [default : `{{ (inventory_dir | realpath + "/../resources/") + "files/by-group/" + netdata__group_name + "/etc/netdata" }}`]. +* **netdata__host_etc_src** : Directory which contains configuration files for Netdata that should be managed on specific host [default : `{{ (inventory_dir | realpath + "/../resources/") + "files/by-host/" + inventory_hostname + "/etc/netdata" }}`]. * **netdata__service_name** : The service name to manage [default : `netdata`]. * **netdata__service_manage** : If the Netdata services should be managed [default : `True`]. * **netdata__conf_bind_ip** : IP address used by Netdata to listen [default : `127.0.0.1`]. @@ -45,28 +49,27 @@ A role to manage Netdata installation and configuration. ``` * Use your own Netdata's configuration as source : - -``` yml -- hosts: mynode.DOMAIN - roles: - - role: ipr-cnrs.netdata - netdata__etc_src: '{{ inventory_dir + "/../resources/host/mynode.DOMAIN/etc/netdata/" }}' -``` - - * Ensure your directory contains only templates or sub-directories, such as : + * Ensure you have resources directory contains only templates or sub-directories, such as : ``` sh -mynode.DOMAIN -└── etc - └── netdata - ├── fping.conf.j2 - ├── health_alarm_notify.conf.j2 - ├── netdata.conf.j2 - └── node.d - ├── named.conf.md.j2 - ├── README.md.j2 - ├── sma_webbox.conf.md.j2 - └── snmp.conf.md.j2 +inventory +├── group_vars +│   ├── all +│   │   ├── ….yml +│   │   └── netdata.yml +│   └── … +resources +├── files +│   ├── by-group +│   │   └── all +│   │   │   ├── etc +│   │   │   │   ├── netdata +│   │   │   │   │   ├── health.d +│   │   │   │   │   │   └── ram.conf.j2 +│   │   │   │   │   ├── plugins.d +│   │   │   │   │   │   └── python.d.plugin +│   │   │   │   │   └── python.d +│   │   │   │   │   └── fail2ban.chart.py ``` * Listen on LAN, be careful, Netdata is not designed to be exposed (see [issue 64][netdata issue 164]) : @@ -83,7 +86,7 @@ mynode.DOMAIN This role will : * Install needed packages to provide `netdata` service. -* Manage Netdata configuration directory (/etc/netdata). +* Manage Netdata configuration directory (/etc/netdata) from several sources (netdata__default_etc_src, netdata__etc_src, netdata__group_etc_src and netdata__host_etc_src). * Ensure Netdata service is enabled and started. * Set up some basics configuration (bind ip, port,…). diff --git a/defaults/main.yml b/defaults/main.yml index b8a37ac..d143218 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -60,14 +60,50 @@ netdata__service_manage: True # Common configuration [[[ # ----------------------------- +# .. envvar:: netdata__group_name [[[. +# +# Name of the directory which contains configuration files which should be +# generated on hosts in a specific group. This variable needs to be set on a +# group level in the inventory to take effect. Only one group is supported at +# a time. +netdata__group_name: 'nonexistent-host-group' + + # ]]] +# .. envvar:: netdata__default_etc_src [[[. +# +# Directory which contains configuration files from this role that should be +# managed on all hosts. +netdata__default_etc_src: '../templates/etc/netdata' + + # ]]] # .. envvar:: netdata__etc_src [[[. -# Directory with templates used to provide Netdata configuration (usually in -# '/etc/netdata'). # -# Must be a relative path to default directory of this role -# or to your ansible inventory directory. +# Directory which contains configuration files that should be managed on all +# hosts in the Ansible inventory. # -netdata__etc_src: '../templates/etc/netdata' +# Must be a relative path to group directory of this role or to your +# ansible inventory directory. +netdata__etc_src: '{{ (inventory_dir | realpath + "/../resources/") + "files/by-group/all/etc/netdata/" }}' + + # ]]] +# .. envvar:: netdata__group_etc_src [[[. +# +# Directory which contains configuration files for Netdata that should be +# managed on hosts in a specific Ansible inventory group. +# +# Must be a relative path to Netdata group directory on your Ansible inventory +# directory. +netdata__group_etc_src: '{{ (inventory_dir | realpath + "/../resources/") + "files/by-group/" + netdata__group_name + "/etc/netdata" }}' + + # ]]] +# .. envvar:: netdata__host_etc_src [[[. +# +# Directory which contains configuration files for Netdata that should be +# managed on specific host in the Ansible inventory for Netdata. +# +# Must be a relative path to Netdata configuration directory for these hosts in +# your Ansible inventory directory. +netdata__host_etc_src: '{{ (inventory_dir | realpath + "/../resources/") + "files/by-host/" + inventory_hostname + "/etc/netdata" }}' # ]]] # .. envvar:: netdata__conf_bind_ip [[[. diff --git a/tasks/main.yml b/tasks/main.yml index 8ac44d8..4fa1a65 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -20,7 +20,11 @@ owner: 'root' group: 'netdata' mode: '0755' - with_filetree: '{{ netdata__etc_src }}' + with_filetree: + - '{{ netdata__host_etc_src }}' + - '{{ netdata__group_etc_src }}' + - '{{ netdata__etc_src }}' + - '{{ netdata__default_etc_src }}' when: (item.state == 'directory') and (netdata__deploy_state == "present") notify: ['Restart Netdata service'] @@ -31,7 +35,11 @@ owner: 'root' group: 'netdata' mode: '{{ item.mode }}' - with_filetree: '{{ netdata__etc_src }}' + with_filetree: + - '{{ netdata__host_etc_src }}' + - '{{ netdata__group_etc_src }}' + - '{{ netdata__etc_src }}' + - '{{ netdata__default_etc_src }}' when: (item.state == 'file') and (netdata__deploy_state == "present") notify: ['Restart Netdata service'] @@ -41,6 +49,10 @@ dest: "/etc/netdata/{{ item.path | replace('.j2','') }}" state: 'link' force: true - with_filetree: '{{ netdata__etc_src }}' + with_filetree: + - '{{ netdata__host_etc_src }}' + - '{{ netdata__group_etc_src }}' + - '{{ netdata__etc_src }}' + - '{{ netdata__default_etc_src }}' when: (item.state == 'link') and (netdata__deploy_state == "present") notify: ['Restart Netdata service'] diff --git a/templates/etc/netdata/netdata.conf.j2 b/templates/etc/netdata/netdata.conf.j2 index b31642a..d4e5aa6 100644 --- a/templates/etc/netdata/netdata.conf.j2 +++ b/templates/etc/netdata/netdata.conf.j2 @@ -1,4 +1,5 @@ ## {{ ansible_managed }} +## From ipr-cnrs.netdata role # NetData Configuration diff --git a/templates/etc/netdata/stream.conf.j2 b/templates/etc/netdata/stream.conf.j2 index 87d2c86..f04d660 100644 --- a/templates/etc/netdata/stream.conf.j2 +++ b/templates/etc/netdata/stream.conf.j2 @@ -1,4 +1,5 @@ ## {{ ansible_managed }} +## From ipr-cnrs.netdata role # netdata configuration for aggregating data from remote hosts #