From 9fc3a461cea01332bd801b357a58641182df514e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Thu, 26 Jul 2018 17:46:10 +0200 Subject: [PATCH] Manage Netdata configuration --- CHANGELOG.md | 1 + README.md | 29 ++++++++++++++++++++++++++- defaults/main.yml | 15 ++++++++++++++ tasks/main.yml | 29 +++++++++++++++++++++++++++ templates/etc/netdata/netdata.conf.j2 | 21 +++++++++++++++++++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 templates/etc/netdata/netdata.conf.j2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0624241..09b406a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,4 @@ ### Features * Install Netdata. * Can choose to install recommends packages. +* Manage Netdata configuration (/etc). diff --git a/README.md b/README.md index 49a46a4..b424230 100644 --- a/README.md +++ b/README.md @@ -17,22 +17,49 @@ 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`]. ## Example Playbook * Use defaults vars : ``` yaml -- hosts: mynode.domain +- hosts: mynode.DOMAIN roles: - role: ipr-cnrs.netdata tags: ['role::netdata', 'ipr'] ``` +* 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 : + +``` 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 +``` + ## Configuration This role will : * Install needed packages to provide `netdata` service. +* Manage Netdata configuration (/etc/netdata). ## Development diff --git a/defaults/main.yml b/defaults/main.yml index f33fca7..898b59a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -37,3 +37,18 @@ netdata__install_recommends: True netdata__deploy_state: 'present' # ]]] # ]]] +# Configuration [[[ +# ----------------------------- + +# .. 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. +# +netdata__etc_src: '../templates/etc/netdata' + + # ]]] + + # ]]] diff --git a/tasks/main.yml b/tasks/main.yml index 5dc2fc6..8673422 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -13,3 +13,32 @@ - '{{ netdata__base_packages }}' +# Server Manage /etc configuration files [[[1 +- name: Ensure Netdata directory structure exists + file: + path: '/etc/netdata/{{ item.path }}' + state: directory + owner: 'root' + group: 'netdata' + mode: '0755' + with_filetree: '{{ netdata__etc_src }}' + when: item.state == 'directory' + +- name: Generate Netdata configuration files + template: + src: '{{ item.src }}' + dest: "/etc/netdata/{{ item.path | replace('.j2','') }}" + owner: 'root' + group: 'netdata' + mode: '{{ item.mode }}' + with_filetree: '{{ netdata__etc_src }}' + when: item.state == 'file' + +- name: Generate Netdata configuration symlinks + template: + src: '{{ item.src }}' + dest: "/etc/netdata/{{ item.path | replace('.j2','') }}" + state: 'link' + force: true + with_filetree: '{{ netdata__etc_src }}' + when: item.state == 'link' diff --git a/templates/etc/netdata/netdata.conf.j2 b/templates/etc/netdata/netdata.conf.j2 new file mode 100644 index 0000000..7bd0886 --- /dev/null +++ b/templates/etc/netdata/netdata.conf.j2 @@ -0,0 +1,21 @@ +## {{ ansible_managed }} + +# NetData Configuration + +# The current full configuration can be retrieved from the running +# server at the URL +# +# http://localhost:19999/netdata.conf +# +# for example: +# +# wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf +# + +[global] + run as user = netdata + web files owner = root + web files group = root + # Netdata is not designed to be exposed to potentially hostile + # networks.See https://github.com/firehol/netdata/issues/164 + bind socket to IP = 127.0.0.1