From 08753b404ebac8bfee3943d52822823c45e5da11 Mon Sep 17 00:00:00 2001 From: guochao Date: Fri, 21 Jul 2017 11:30:39 +0800 Subject: [PATCH] Support customizing grafana home dashboard Replace grafana home dashboard with file in node_custom_config folder. Change-Id: I00e3963ee287c526935e34169b63b1a40e6b4025 --- ansible/roles/grafana/handlers/main.yml | 1 + ansible/roles/grafana/tasks/config.yml | 14 ++++++++++++++ ansible/roles/grafana/templates/grafana.json.j2 | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/ansible/roles/grafana/handlers/main.yml b/ansible/roles/grafana/handlers/main.yml index 209152bf3e..58918dd996 100644 --- a/ansible/roles/grafana/handlers/main.yml +++ b/ansible/roles/grafana/handlers/main.yml @@ -19,3 +19,4 @@ - config_json.changed | bool or grafana_conf.changed | bool or grafana_container.changed | bool + or grafana_home_dashboard.changed | bool diff --git a/ansible/roles/grafana/tasks/config.yml b/ansible/roles/grafana/tasks/config.yml index 4cb50c3760..13b0e51878 100644 --- a/ansible/roles/grafana/tasks/config.yml +++ b/ansible/roles/grafana/tasks/config.yml @@ -38,6 +38,20 @@ notify: - Restart grafana container +- name: Check if custom grafana home dashboard exists + local_action: "stat path={{ node_custom_config }}/grafana/grafana_home_dashboard.json" + 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" + register: grafana_home_dashboard + when: grafana_custom_dashboard_file.stat.exists + notify: + - Restart grafana container + - name: Check grafana containers kolla_docker: action: "compare_container" diff --git a/ansible/roles/grafana/templates/grafana.json.j2 b/ansible/roles/grafana/templates/grafana.json.j2 index d9a75b8bc0..2b83af7471 100644 --- a/ansible/roles/grafana/templates/grafana.json.j2 +++ b/ansible/roles/grafana/templates/grafana.json.j2 @@ -6,6 +6,13 @@ "dest": "/etc/grafana/grafana.ini", "owner": "grafana", "perm": "0600" + }, + { + "source": "{{ container_config_directory }}/grafana_home_dashboard.json", + "dest": "/usr/share/grafana/public/dashboards/home.json", + "owner": "root", + "perm": "0644", + "optional": true } ], "permissions": [