forked from UCCNetsoc/NaC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export-grafana-dashboards.yml
55 lines (49 loc) · 1.6 KB
/
export-grafana-dashboards.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
- name: Export Grafana Dashboards
hosts: web.infra.netsoc.co
tasks:
- name: Get all Grafana dashboards
uri:
url: "{{ url }}/api/search?query=&starred=false&skipRecent=true&skipStarred=true&prevSort=null"
force_basic_auth: yes
user: admin
password: "{{ grafana.password }}"
register: dashboards
- name: Export Grafana dashboards
community.grafana.grafana_dashboard:
state: export
grafana_url: "{{ url }}"
url_username: admin
url_password: "{{ grafana.password }}"
uid: "{{ item.uid }}"
path: "/netsoc/grafana/exports/{{ item.uri }}.json"
with_items: "{{ dashboards.json }}"
become: yes
- name: Fetch dashboards to NaC/roles/grafana/files/data/dashboards
fetch:
src: "/netsoc/grafana/exports/{{ item.uri }}.json"
dest: "./roles/grafana/files/data/dashboards/{{ item.uri | basename }}.json"
flat: yes
with_items: "{{ dashboards.json }}"
become: yes
vars_files:
- "vars/network.yml"
- "vars/secrets_mapping.yml"
- "vars/secrets.yml"
vars:
url: https://grafana.netsoc.co
- name: Format Dashboards
hosts: localhost
tasks:
- name: Get dashboard files
become: no
find:
path: "{{ playbook_dir }}/roles/grafana/files/data/dashboards"
recurse: no
register: dashboards_dir
- name: Format dashboard files
become: no
shell: "cat <<< $(jq .dashboard {{ item.path }} | jq '.id = null' ) > {{ item.path }}"
args:
executable: /bin/bash
with_items: "{{ dashboards_dir.files }}"