summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--roles/monitoring/grafana/tasks/main.yml17
1 files changed, 16 insertions, 1 deletions
diff --git a/roles/monitoring/grafana/tasks/main.yml b/roles/monitoring/grafana/tasks/main.yml
index 30f1348e..48a0ec96 100644
--- a/roles/monitoring/grafana/tasks/main.yml
+++ b/roles/monitoring/grafana/tasks/main.yml
@@ -81,7 +81,7 @@
no_log: yes
notify: restart grafana
-- name: install datasources
+- name: configure dashboard provisioning
copy:
dest: "/etc/grafana/provisioning/dashboards/ansible.yml"
content: |
@@ -110,6 +110,7 @@
copy:
content: "{{ lookup('file', 'dashboard-'+item.file+'.json') | regex_replace('\"(?:\\${)?DS_[A-Z0-9_-]+(?:})?\"', '\"'+item.datasource+'\"') }}\n"
dest: "/var/lib/grafana/dashboards/ansible/{{ item.datasource }}_{{ item.file }}.json"
+ register: grafana_dasboards_from_file
- name: install dashboards from content
loop: "{{ grafana_dashboards | selectattr('content', 'defined') }}"
@@ -118,6 +119,7 @@
copy:
content: "{{ item.content | regex_replace('\"(?:\\${)?DS_[A-Z0-9_-]+(?:})?\"', '\"'+item.datasource+'\"') }}\n"
dest: "/var/lib/grafana/dashboards/ansible/{{ item.datasource }}_{{ item.name }}.json"
+ register: grafana_dasboards_from_content
## TODO: implement this
- name: install dashboards from grafana.com
@@ -126,6 +128,19 @@
label: "https://grafana.com/api/dashboards/{{ item.id }} -> {{ item.datasource }}"
debug:
msg: 'installing dashboards from grafana.com is not yet supported!'
+ # register: grafana_dasboards_from_grafanacom
+
+- name: fetch list of installed dashboards
+ find:
+ paths: /var/lib/grafana/dashboards/ansible
+ patterns: "*.json"
+ register: grafana_dashboards_installed
+
+- name: remove superfluous dashboards
+ loop: "{{ grafana_dashboards_installed.files | map(attribute='path') | difference(grafana_dasboards_from_file.results | map(attribute='dest')) | difference(grafana_dasboards_from_content.results | map(attribute='dest')) | list }}"
+ file:
+ path: "{{ item }}"
+ state: absent
- name: make sure grafana-server is enabled and started
systemd: