Newer
Older
---
- name: Ensuring config directories exist
file:
path: "{{ node_config_directory }}/{{ item.key }}"
owner: "{{ config_owner_user }}"
group: "{{ config_owner_group }}"
mode: "0770"
become: true
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ grafana_services }}"
- name: Check if extra configuration file exists
find:
path: "{{ node_custom_config }}/grafana/"
delegate_to: localhost
changed_when: False
run_once: True
register: check_extra_conf_grafana
when:
- kolla_copy_ca_into_containers | bool
src: "{{ item.key }}.json.j2"
dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
mode: "0660"
become: true
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ grafana_services }}"
notify:
merge_configs:
sources:
- "{{ role_path }}/templates/grafana.ini.j2"
- "{{ node_custom_config }}/{{ item.key }}.ini"
- "{{ node_custom_config }}/grafana/{{ inventory_hostname }}/{{ item.key }}.ini"
dest: "{{ node_config_directory }}/grafana/grafana.ini"
mode: "0660"
become: true
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ grafana_services }}"
notify:
- name: Copying over extra configuration file
become: true
template:
src: "{{ item.path }}"
dest: "{{ node_config_directory }}/grafana/{{ item.path | basename }}"
mode: "0660"
when:
- item is defined
with_items:
- "{{ check_extra_conf_grafana.files }}"
notify:
- name: Check if custom grafana home dashboard exists
stat:
path: "{{ node_custom_config }}/grafana/grafana_home_dashboard.json"
delegate_to: localhost
register: grafana_custom_dashboard_file
run_once: True
- name: Copying over grafana home dashboard if exists
template:
src: "{{ node_custom_config }}/grafana/grafana_home_dashboard.json"
dest: "{{ node_config_directory }}/grafana/grafana_home_dashboard.json"
when: grafana_custom_dashboard_file.stat.exists
notify:
- name: Configuring Prometheus as data source for Grafana
vars:
service: "{{ grafana_services['grafana'] }}"
template:
src: "{{ item }}"
dest: "{{ node_config_directory }}/grafana/prometheus.yaml"
mode: "0660"
become: true
when:
- inventory_hostname in groups[service.group]
- service.enabled | bool
- enable_prometheus | bool
with_first_found:
- "{{ node_custom_config }}/grafana/{{ inventory_hostname }}/prometheus.yaml"
- "{{ node_custom_config }}/grafana/prometheus.yaml"
- "prometheus.yaml.j2"
notify:
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
163
164
165
166
167
168
169
170
171
172
- name: Configuring dashboards provisioning
vars:
service: "{{ grafana_services['grafana'] }}"
template:
src: "{{ item }}"
dest: "{{ node_config_directory }}/grafana/provisioning.yaml"
mode: "0660"
become: true
when:
- inventory_hostname in groups[service.group]
- service.enabled | bool
with_first_found:
- "{{ node_custom_config }}/grafana/{{ inventory_hostname }}/provisioning.yaml"
- "{{ node_custom_config }}/grafana/provisioning.yaml"
- "{{ role_path }}/templates/provisioning.yaml.j2"
notify:
- Restart grafana container
- name: Check if the folder for custom grafana dashboards exists
stat:
path: "{{ node_custom_config }}/grafana/dashboards"
delegate_to: localhost
register: grafana_custom_dashboards_folder
run_once: True
- name: Remove templated Grafana dashboards
become: true
vars:
service: "{{ grafana_services['grafana'] }}"
file:
state: absent
path: "{{ node_config_directory }}/grafana/dashboards/"
when:
- inventory_hostname in groups[service.group]
- service.enabled | bool
- name: Create custom Grafana dashboards folder
become: true
vars:
service: "{{ grafana_services['grafana'] }}"
file:
dest: "{{ node_config_directory }}/grafana/dashboards/"
state: "directory"
mode: "0770"
when:
- grafana_custom_dashboards_folder.stat.exists
- grafana_custom_dashboards_folder.stat.isdir
- inventory_hostname in groups[service.group]
- service.enabled | bool
- name: Copying over custom dashboards
vars:
service: "{{ grafana_services['grafana'] }}"
copy:
src: "{{ item }}"
dest: "{{ node_config_directory }}/grafana/dashboards/"
mode: "0660"
become: true
when:
- grafana_custom_dashboards_folder.stat.exists
- grafana_custom_dashboards_folder.stat.isdir
- inventory_hostname in groups[service.group]
- service.enabled | bool
with_fileglob:
- "{{ node_custom_config }}/grafana/dashboards/*.json"
notify:
- Restart grafana container