grafana: prune stale dashboard files from prom on each apply
Without this, a renamed dashboard left the old file on disk and the provisioner refused to write any dashboards because of a duplicate UID (seen with towerops-phoenix-live-view vs towerops-phoenix_live_view).
This commit is contained in:
parent
6fa9085b18
commit
5443e75d70
1 changed files with 28 additions and 0 deletions
|
|
@ -69,6 +69,34 @@
|
|||
mode: "0644"
|
||||
notify: Restart grafana
|
||||
|
||||
- name: List currently-provisioned dashboard files on host
|
||||
ansible.builtin.find:
|
||||
paths: "{{ grafana_dashboards_dir }}"
|
||||
patterns: "*.json"
|
||||
file_type: file
|
||||
register: grafana_remote_dashboards
|
||||
|
||||
- name: List dashboard JSON files from this role
|
||||
ansible.builtin.set_fact:
|
||||
grafana_managed_dashboards: >-
|
||||
{{
|
||||
query('ansible.builtin.fileglob',
|
||||
role_path ~ '/files/dashboards/*.json')
|
||||
| map('basename') | list
|
||||
}}
|
||||
|
||||
# Without this, a renamed dashboard leaves the old file on disk and the
|
||||
# provisioner refuses to write any dashboards (duplicate UID warning).
|
||||
- name: Remove stale dashboard files not present in the role
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
state: absent
|
||||
loop: "{{ grafana_remote_dashboards.files }}"
|
||||
loop_control:
|
||||
label: "{{ item.path | basename }}"
|
||||
when: (item.path | basename) not in grafana_managed_dashboards
|
||||
notify: Restart grafana
|
||||
|
||||
- name: Render dashboard provider config
|
||||
ansible.builtin.template:
|
||||
src: dashboard-providers.yaml.j2
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue