Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy dashboards to the server before importing them when grafana_use_provisioning is false #235

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions roles/grafana/tasks/dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,40 @@
loop: "{{ grafana_dashboards }}"

- name: "Import grafana dashboards via api"
community.grafana.grafana_dashboard:
grafana_url: "{{ grafana_api_url }}"
grafana_user: "{{ grafana_security.admin_user }}"
grafana_password: "{{ grafana_security.admin_password }}"
path: "{{ item }}"
message: "Updated by ansible role {{ ansible_role_name }}"
state: present
overwrite: true
no_log: "{{ 'false' if lookup('env', 'CI') else 'true' }}"
with_fileglob:
- "{{ __tmp_dashboards.path }}/*"
- "{{ grafana_dashboards_dir }}/*.json"
block:
- name: "Create temporary directory for dashboards"
ansible.builtin.tempfile:
prefix: grafana.grafana.grafana.
state: directory
changed_when: false
register: __tmp_dashboards_import

- name: "Copy dashboards to the temporary directory"
ansible.builtin.copy:
src: "{{ grafana_dashboards_dir }}/"
dest: "{{ __tmp_dashboards_import.path }}/"
mode: "0440"

- name: "Import dashboards via api"
community.grafana.grafana_dashboard:
grafana_url: "{{ grafana_api_url }}"
grafana_user: "{{ grafana_security.admin_user }}"
grafana_password: "{{ grafana_security.admin_password }}"
path: "{{ item }}"
commit_message: "Updated by ansible role {{ ansible_role_name }}"
state: present
overwrite: true
no_log: "{{ 'false' if lookup('env', 'CI') else 'true' }}"
with_fileglob:
- "{{ __tmp_dashboards.path }}/*"
- "{{ __tmp_dashboards_import.path }}/*.json"
always:
- name: "Clean up the temporary directory"
ansible.builtin.file:
path: "{{ __tmp_dashboards_import.path }}"
state: absent
when: __tmp_dashboards_import is defined
changed_when: false
when: "not grafana_use_provisioning"

- name: "Import grafana dashboards through provisioning"
Expand Down