aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'tasks')
-rw-r--r--tasks/config.yml162
-rw-r--r--tasks/main.yml4
2 files changed, 166 insertions, 0 deletions
diff --git a/tasks/config.yml b/tasks/config.yml
new file mode 100644
index 0000000..4ada6e6
--- /dev/null
+++ b/tasks/config.yml
@@ -0,0 +1,162 @@
1- name: Run specific tasks
2 include_tasks: "{{ item.specific_task_file }}"
3 when: item.specific_task_file is defined
4 loop: "{{ netdata_extra_config }}"
5
6- name: Configure plugins apt dependencies
7 apt:
8 name: "{{ netdata_plugins_apt }}"
9 state: present
10 vars:
11 netdata_plugins_apt: "{{ netdata_extra_config | map(attribute='apt_dependencies') |
12 reject('undefined') | list | flatten | unique }}"
13 register: netdata_plugins_apt_deps_st
14 until: netdata_plugins_apt_deps_st is succeeded
15
16- name: Get list of pip dependencies
17 set_fact:
18 netdata_plugins_pip: "{{ netdata_extra_config | map(attribute='pip_dependencies') |
19 reject('undefined') | list | flatten | unique }}"
20
21- name: Install pip for python dependencies
22 apt:
23 name: "{{ python_package }}"
24 state: present
25 when:
26 - netdata_plugins_pip|length > 0
27 - ansible_os_family == 'Debian'
28 vars:
29 python_package: "{{ netdata_pip_package[ansible_distribution ~ ansible_distribution_version] | default('python-pip') }}"
30 register: netdata_pip_install
31 until: netdata_pip_install is succeeded
32
33- name: Configure plugins pip dependencies
34 pip:
35 name: "{{ netdata_plugins_pip }}"
36 state: present
37 when: netdata_plugins_pip|length > 0
38 register: netdata_plugins_pip_deps_st
39 until: netdata_plugins_pip_deps_st is succeeded
40
41- name: Add netdata to extra groups
42 user:
43 name: netdata
44 groups: "{{ netdata_plugins_groups }}"
45 append: yes
46 notify: restart netdata
47 vars:
48 netdata_plugins_groups: "{{ netdata_extra_config | map(attribute='extra_groups') |
49 reject('undefined') | list | flatten | unique }}"
50
51- name: Get list of files to grant read on
52 set_fact:
53 netdata_plugins_files: "{{ netdata_extra_config | map(attribute='read_files') |
54 reject('undefined') | list | flatten | unique }}"
55
56- name: Install acl if files need to be granted access
57 apt:
58 name: acl
59 state: present
60 when: netdata_plugins_files|length > 0
61
62- name: Grant read acces to files
63 acl:
64 path: "{{ item }}"
65 entity: netdata
66 etype: user
67 permissions: r
68 state: present
69 notify: restart netdata
70 loop: "{{ netdata_plugins_files }}"
71
72- name: Configure plugins
73 copy:
74 dest: "{{ netdata_collector_conf_dir }}/{{ collector.name }}.conf"
75 content: "{{ content[collector.format | default('yaml')] }}"
76 mode: 0640
77 owner: netdata
78 when: collector.config is defined
79 notify: restart netdata
80 loop: "{{ netdata_extra_config }}"
81 loop_control:
82 loop_var: collector
83 label: "{{ collector.name }}"
84 vars:
85 netdata_collector_conf_dir: "/etc/netdata/{{ collector.type }}.d"
86 bash_content_tmp: "{{ collector.config.items() | sort | list | map('join','=') | list }}"
87 bash_content: "{{ bash_content_tmp | map('regex_replace','(.*)=(.*)',collector.name ~ '_\\1=\\2') | join('\n') }}"
88 yaml_content: "{{ collector.config | to_nice_yaml }}"
89 json_content: "{{ collector.config | to_nice_json }}"
90 content:
91 bash: "{{ bash_content ~ '\n' }}"
92 json: "{{ json_content }}"
93 yaml: "{{ yaml_content }}"
94 no_log: "{{ collector.no_log | default(false) }}"
95
96- name: Remove old config
97 file:
98 path: "{{ netdata_old_collector_conf_dir }}/{{ collector.name }}.conf"
99 state: absent
100 when: collector.replace is defined
101 notify: restart netdata
102 loop: "{{ netdata_extra_config }}"
103 loop_control:
104 loop_var: collector
105 label: "{{ collector.name }}"
106 vars:
107 netdata_old_collector_conf_dir: "/etc/netdata/{{ collector.replace }}.d"
108
109- name: Configure chart
110 copy:
111 dest: "{{ netdata_collector_chart_dir }}"
112 src: "{{ collector.chart_name }}.chart.sh"
113 mode: 0755
114 owner: netdata
115 when: collector.chart_name is defined
116 notify: restart netdata
117 loop: "{{ netdata_extra_config }}"
118 loop_control:
119 loop_var: collector
120 label: "{{ collector.name }}"
121 vars:
122 netdata_collector_chart_dir: "/usr/libexec/netdata/charts.d/"
123
124- name: Configure plugins health
125 template:
126 dest: "{{ netdata_health_conf_dir }}/{{ collector.name }}.conf"
127 src: health_template.j2
128 mode: 0640
129 owner: netdata
130 when: collector.health_config is defined
131 notify: restart netdata # a reload would be enough
132 loop: "{{ netdata_extra_config }}"
133 loop_control:
134 loop_var: collector
135 label: "{{ collector.name }}"
136
137- name: Configure overrides
138 copy:
139 dest: "{{ netdata_health_conf_dir }}/{{ override.name }}.conf"
140 content: |
141 # {{ override.name }}
142 {{ override.override }}
143 mode: 0640
144 owner: netdata
145 notify: reload netdata
146 loop: "{{ netdata_alarms_overrides }}"
147 loop_control:
148 loop_var: override
149 label: "{{ override.name }}"
150
151- name: Configure alarm
152 template:
153 dest: "{{ netdata_health_conf_dir }}/{{ collector.name }}.conf"
154 src: "netdata_alarm.conf.j2"
155 mode: 0755
156 owner: netdata
157 when: collector.alarm_config is defined
158 notify: restart netdata
159 loop: "{{ netdata_extra_config }}"
160 loop_control:
161 loop_var: collector
162 label: "{{ collector.name }}"
diff --git a/tasks/main.yml b/tasks/main.yml
index ca849a3..f05eff4 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -65,3 +65,7 @@
65 - netdata_alarm_notify_configs is defined 65 - netdata_alarm_notify_configs is defined
66 - netdata_alarm_notify_configs | count > 0 66 - netdata_alarm_notify_configs | count > 0
67 notify: restart netdata 67 notify: restart netdata
68
69- name: Configure netdata sensors
70 include_tasks: config.yml
71 when: (netdata_extra_config|length > 0) or (netdata_alarms_overrides|length > 0)