aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks/config.yml
blob: 4ada6e659417cb5170422632a7a71359b4d718a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
- name: Run specific tasks
  include_tasks: "{{ item.specific_task_file }}"
  when: item.specific_task_file is defined
  loop: "{{ netdata_extra_config }}"

- name: Configure plugins apt dependencies
  apt:
    name: "{{ netdata_plugins_apt }}"
    state: present
  vars:
    netdata_plugins_apt: "{{ netdata_extra_config | map(attribute='apt_dependencies') |
                          reject('undefined') | list | flatten | unique }}"
  register: netdata_plugins_apt_deps_st
  until: netdata_plugins_apt_deps_st is succeeded

- name: Get list of pip dependencies
  set_fact:
    netdata_plugins_pip: "{{ netdata_extra_config | map(attribute='pip_dependencies') |
                          reject('undefined') | list | flatten | unique }}"

- name: Install pip for python dependencies
  apt:
    name: "{{ python_package }}"
    state: present
  when:
    - netdata_plugins_pip|length > 0
    - ansible_os_family == 'Debian'
  vars:
    python_package: "{{ netdata_pip_package[ansible_distribution ~ ansible_distribution_version] | default('python-pip') }}"
  register: netdata_pip_install
  until: netdata_pip_install is succeeded

- name: Configure plugins pip dependencies
  pip:
    name: "{{ netdata_plugins_pip }}"
    state: present
  when: netdata_plugins_pip|length > 0
  register: netdata_plugins_pip_deps_st
  until: netdata_plugins_pip_deps_st is succeeded

- name: Add netdata to extra groups
  user:
    name: netdata
    groups: "{{ netdata_plugins_groups }}"
    append: yes
  notify: restart netdata
  vars:
    netdata_plugins_groups: "{{ netdata_extra_config | map(attribute='extra_groups') |
                             reject('undefined') | list | flatten | unique }}"

- name: Get list of files to grant read on
  set_fact:
    netdata_plugins_files: "{{ netdata_extra_config | map(attribute='read_files') |
                             reject('undefined') | list | flatten | unique }}"

- name: Install acl if files need to be granted access
  apt:
    name: acl
    state: present
  when: netdata_plugins_files|length > 0

- name: Grant read acces to files
  acl:
    path: "{{ item }}"
    entity: netdata
    etype: user
    permissions: r
    state: present
  notify: restart netdata
  loop: "{{ netdata_plugins_files }}"

- name: Configure plugins
  copy:
    dest: "{{ netdata_collector_conf_dir }}/{{ collector.name }}.conf"
    content: "{{ content[collector.format | default('yaml')] }}"
    mode: 0640
    owner: netdata
  when: collector.config is defined
  notify: restart netdata
  loop: "{{ netdata_extra_config }}"
  loop_control:
    loop_var: collector
    label: "{{ collector.name }}"
  vars:
    netdata_collector_conf_dir: "/etc/netdata/{{ collector.type }}.d"
    bash_content_tmp: "{{ collector.config.items() | sort | list | map('join','=') | list }}"
    bash_content: "{{ bash_content_tmp | map('regex_replace','(.*)=(.*)',collector.name ~ '_\\1=\\2') | join('\n') }}"
    yaml_content: "{{ collector.config | to_nice_yaml }}"
    json_content: "{{ collector.config | to_nice_json }}"
    content:
      bash: "{{ bash_content ~ '\n' }}"
      json: "{{ json_content }}"
      yaml: "{{ yaml_content }}"
  no_log: "{{ collector.no_log | default(false) }}"

- name: Remove old config
  file:
    path: "{{ netdata_old_collector_conf_dir }}/{{ collector.name }}.conf"
    state: absent
  when: collector.replace is defined
  notify: restart netdata
  loop: "{{ netdata_extra_config }}"
  loop_control:
    loop_var: collector
    label: "{{ collector.name }}"
  vars:
    netdata_old_collector_conf_dir: "/etc/netdata/{{ collector.replace }}.d"

- name: Configure chart
  copy:
    dest: "{{ netdata_collector_chart_dir }}"
    src: "{{ collector.chart_name }}.chart.sh"
    mode: 0755
    owner: netdata
  when: collector.chart_name is defined
  notify: restart netdata
  loop: "{{ netdata_extra_config }}"
  loop_control:
    loop_var: collector
    label: "{{ collector.name }}"
  vars:
    netdata_collector_chart_dir: "/usr/libexec/netdata/charts.d/"

- name: Configure plugins health
  template:
    dest: "{{ netdata_health_conf_dir }}/{{ collector.name }}.conf"
    src: health_template.j2
    mode: 0640
    owner: netdata
  when: collector.health_config is defined
  notify: restart netdata # a reload would be enough
  loop: "{{ netdata_extra_config }}"
  loop_control:
    loop_var: collector
    label: "{{ collector.name }}"

- name: Configure overrides
  copy:
    dest: "{{ netdata_health_conf_dir }}/{{ override.name }}.conf"
    content: |
      # {{ override.name }}
      {{ override.override }}
    mode: 0640
    owner: netdata
  notify: reload netdata
  loop: "{{ netdata_alarms_overrides }}"
  loop_control:
    loop_var: override
    label: "{{ override.name }}"

- name: Configure alarm
  template:
    dest: "{{ netdata_health_conf_dir }}/{{ collector.name }}.conf"
    src: "netdata_alarm.conf.j2"
    mode: 0755
    owner: netdata
  when: collector.alarm_config is defined
  notify: restart netdata
  loop: "{{ netdata_extra_config }}"
  loop_control:
    loop_var: collector
    label: "{{ collector.name }}"