diff --git a/ansible/roles/grafana/tasks/config.yml b/ansible/roles/grafana/tasks/config.yml index cf5cd23efc..ef88e83cde 100644 --- a/ansible/roles/grafana/tasks/config.yml +++ b/ansible/roles/grafana/tasks/config.yml @@ -12,6 +12,9 @@ - name: Check if extra configuration file exists find: path: "{{ node_custom_config }}/grafana/" + excludes: + - "prometheus.yaml" + - "provisioning.yaml" delegate_to: localhost changed_when: False run_once: True @@ -59,23 +62,6 @@ notify: - Restart grafana container -- 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 - become: true - template: - src: "{{ node_custom_config }}/grafana/grafana_home_dashboard.json" - dest: "{{ node_config_directory }}/grafana/grafana_home_dashboard.json" - mode: "0660" - when: grafana_custom_dashboard_file.stat.exists - notify: - - Restart grafana container - - name: Configuring Prometheus as data source for Grafana vars: service: "{{ grafana_services['grafana'] }}" diff --git a/ansible/roles/grafana/tasks/post_config.yml b/ansible/roles/grafana/tasks/post_config.yml index 82993cecf7..97a9bc818d 100644 --- a/ansible/roles/grafana/tasks/post_config.yml +++ b/ansible/roles/grafana/tasks/post_config.yml @@ -57,4 +57,4 @@ register: grafana_response changed_when: grafana_response.status == 200 run_once: true - when: grafana_custom_dashboard_file.stat.exists + when: "'grafana_home_dashboard.json' in check_extra_conf_grafana.files | map(attribute='path') | map('basename')" diff --git a/ansible/roles/grafana/templates/grafana.json.j2 b/ansible/roles/grafana/templates/grafana.json.j2 index fcc3cc34bb..e685eacd56 100644 --- a/ansible/roles/grafana/templates/grafana.json.j2 +++ b/ansible/roles/grafana/templates/grafana.json.j2 @@ -7,21 +7,22 @@ "owner": "grafana", "perm": "0600" }, -{% if check_extra_conf_grafana is defined %}{% if check_extra_conf_grafana.matched > 0 %}{% for plugin in check_extra_conf_grafana.files %} +{% if check_extra_conf_grafana is defined %} +{% for extra_conf in check_extra_conf_grafana.files | map(attribute='path') | map('basename') %} { - "source": "{{ container_config_directory }}/{{ plugin.path | basename }}", - "dest": "/etc/grafana/{{ plugin.path | basename }}", - "owner": "grafana", - "perm": "0600" - }, -{% endfor %}{% endif %}{% endif %} - { - "source": "{{ container_config_directory }}/grafana_home_dashboard.json", + "source": "{{ container_config_directory }}/{{ extra_conf }}", +{% if extra_conf == 'grafana_home_dashboard.json' %} "dest": "/usr/share/grafana/public/dashboards/home.json", "owner": "root", - "perm": "0644", - "optional": true + "perm": "0644" +{% else %} + "dest": "/etc/grafana/{{ extra_conf }}", + "owner": "grafana", + "perm": "0600" +{% endif %} }, +{% endfor %} +{% endif %} { "source": "{{ container_config_directory }}/prometheus.yaml", "dest": "/etc/grafana/provisioning/datasources/prometheus.yaml", diff --git a/releasenotes/notes/bug-2067999-5d009f15e1cc3185.yaml b/releasenotes/notes/bug-2067999-5d009f15e1cc3185.yaml new file mode 100644 index 0000000000..ef1c80441d --- /dev/null +++ b/releasenotes/notes/bug-2067999-5d009f15e1cc3185.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixes redundant copying of grafana custom config files. + `LP#2067999 `__