Combine 4 vars to generate Netdata configuration

This commit is contained in:
Jeremy Gardais 2018-08-06 14:54:42 +02:00
parent 9a35df05b4
commit ded78c8625
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
6 changed files with 84 additions and 30 deletions

View File

@ -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.

View File

@ -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,…).

View File

@ -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 [[[.

View File

@ -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']

View File

@ -1,4 +1,5 @@
## {{ ansible_managed }}
## From ipr-cnrs.netdata role
# NetData Configuration

View File

@ -1,4 +1,5 @@
## {{ ansible_managed }}
## From ipr-cnrs.netdata role
# netdata configuration for aggregating data from remote hosts
#