Skip to content

Commit 2d16356

Browse files
committed
cleaned up dashboard role
1 parent f23c2fc commit 2d16356

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

ansible/roles/grafana-dashboards/tasks/main.yml

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# SOFTWARE.
2424

2525
- become: false
26+
delegate_to: localhost
2627
block:
2728
- name: Create local grafana dashboard directory
2829
file:
@@ -108,35 +109,10 @@
108109
when:
109110
- grafana_dashboards | length > 0
110111

111-
# Templating partial manifests and then adding the dashboard's data server-side because the k8s module doesn't like Jinja2
112-
- name: Create partial configmaps for server-side templating
113-
ansible.builtin.template:
114-
src: configmap-template.yml.j2
115-
dest: "{{ _tmp_dashboards.path }}/{{ item_filename }}.yml"
116-
loop: "{{ grafana_dashboards }}"
117-
vars:
118-
item_filename: "{{ ((item.dashboard_id | string) + '.json') if 'dashboard_id' in item else item.dashboard_file }}"
119-
120-
- name: Setting data keys
121-
ansible.builtin.replace:
122-
path: "{{ _tmp_dashboards.path }}/{{ item_filename }}.yml"
123-
regexp: 'PLACEHOLDER'
124-
replace: "{{ item_filename }}"
125-
loop: "{{ grafana_dashboards }}"
126-
vars:
127-
item_filename: "{{ ((item.dashboard_id | string) + '.json') if 'dashboard_id' in item else item.dashboard_file }}"
128-
129-
- name: Appending json data to configmaps
130-
ansible.builtin.shell:
131-
cmd: "sed 's/^/ /' {{ item_path }} >> {{ item_path }}.yml"
132-
loop: "{{ grafana_dashboards }}"
133-
vars:
134-
item_filename: "{{ ((item.dashboard_id | string) + '.json') if 'dashboard_id' in item else item.dashboard_file }}"
135-
item_path: "{{ _tmp_dashboards.path }}/{{ item_filename }}"
136-
137-
- name: Applying dashboard configmaps
112+
- name: Template configmaps from dashboards
138113
ansible.builtin.k8s:
139-
src: "{{ item_path }}.yml"
114+
definition:
115+
"{{ lookup('ansible.builtin.template', 'configmap-template.yml.j2') | from_yaml }}"
140116
loop: "{{ grafana_dashboards }}"
141117
vars:
142118
item_filename: "{{ ((item.dashboard_id | string) + '.json') if 'dashboard_id' in item else item.dashboard_file }}"

ansible/roles/grafana-dashboards/templates/configmap-template.yml.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ metadata:
66
labels:
77
grafana_dashboard: "1"
88
data:
9-
PLACEHOLDER: |
9+
{{ item_filename }}: |
10+
{{ lookup('ansible.builtin.file', _tmp_dashboards.path+'/'+item_filename) | indent(4, first=True) }}

0 commit comments

Comments
 (0)