This repository was archived by the owner on May 31, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +81
-4
lines changed Expand file tree Collapse file tree 6 files changed +81
-4
lines changed Original file line number Diff line number Diff line change @@ -15,14 +15,16 @@ Provision and manage [grafana](https://github.com/grafana/grafana) - platform fo
1515- Ansible >= 2.5
1616- libselinux-python on deployer host (only when deployer machine has SELinux)
1717- grafana >= 5.1 (for older grafana versions use this role in version 0.10.1 or earlier)
18+ - rsync if you plan to use grafana provisioning
1819
1920## Role Variables
2021
2122All variables which can be overridden are stored in [ defaults/main.yml] ( defaults/main.yml ) file as well as in table below.
2223
2324| Name | Default Value | Description |
2425| -------------- | ------------- | -----------------------------------|
25- | ` grafana_use_provisioning ` | true | Use Grafana provisioning capalibity when possible (** grafana_version=latest will assume >= 5.0** ) |
26+ | ` grafana_use_provisioning ` | true | Use Grafana provisioning capalibity when possible (** grafana_version=latest will assume >= 5.0** ). |
27+ | ` grafana_provisioning_synced ` | false | Ensure no previously provisioned dashboards are kept if not referenced anymore. |
2628| ` grafana_system_user ` | grafana | Grafana server system user |
2729| ` grafana_system_group ` | grafana | Grafana server system group |
2830| ` grafana_version ` | latest | Grafana package version |
Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ grafana_yum_repo_template: etc/yum.repos.d/grafana.repo.j2
55# Should we use the provisioning capability when possible (provisioning require grafana >= 5.0)
66grafana_use_provisioning : true
77
8+ # Should the provisioning be kept synced. If true, previous provisioned objects will be removed if not referenced anymore.
9+ grafana_provisioning_synced : false
10+
811grafana_instance : " {{ ansible_fqdn | default(ansible_host) | default(inventory_hostname) }}"
912
1013grafana_logs_dir : " /var/log/grafana"
Original file line number Diff line number Diff line change 44 service :
55 name : grafana-server
66 state : restarted
7+
8+ - name : Set privileges on provisioned dashboards
9+ become : true
10+ file :
11+ path : " /var/lib/grafana/dashboards"
12+ recurse : true
13+ owner : grafana
14+ group : grafana
15+ mode : 0640
16+ listen : " provisioned dashboards changed"
17+
18+ - name : Set privileges on provisioned dashboards directory
19+ become : true
20+ file :
21+ path : " /var/lib/grafana/dashboards"
22+ state : directory
23+ recurse : false
24+ mode : 0755
25+ listen : " provisioned dashboards changed"
Original file line number Diff line number Diff line change 22- name : Prepare
33 hosts : all
44 gather_facts : false
5- tasks : []
5+ tasks :
6+ - name : Install rsync for grafana dashboard provisioning
7+ package :
8+ name : ["rsync"]
Original file line number Diff line number Diff line change 11---
2+ - name : Empty local grafana dashboard directory
3+ become : false
4+ file :
5+ path : /tmp/dashboards
6+ state : absent
7+ delegate_to : localhost
8+ run_once : true
9+ check_mode : false
10+ changed_when : false
11+ when : grafana_use_provisioning and grafana_provisioning_synced
12+
213- name : Create local grafana dashboard directories
314 become : false
415 file :
819 delegate_to : localhost
920 run_once : true
1021 check_mode : false
22+ changed_when : false
1123
1224# - name: download grafana dashboard from grafana.net to local folder
1325# become: false
96108 - " {{ grafana_dashboards_dir }}/*.json"
97109 delegate_to : localhost
98110 run_once : true
111+ changed_when : false
99112
100- - name : import grafana dashboards
113+ - name : import grafana dashboards through API
101114 uri :
102115 url : " {{ grafana_api_url }}/api/dashboards/db"
103116 user : " {{ grafana_security.admin_user }}"
109122 no_log : true
110123 with_fileglob :
111124 - " /tmp/dashboards/*"
125+ when : not grafana_use_provisioning
112126
113127# TODO: uncomment this when ansible 2.7 will be min supported version
114128# - name: import grafana dashboards
123137# no_log: true
124138# with_fileglob:
125139# - "/tmp/dashboards/*"
140+
141+ - name : Create/Update dashboards file (provisioning)
142+ become : true
143+ copy :
144+ dest : " /etc/grafana/provisioning/dashboards/ansible.yml"
145+ content : |
146+ apiVersion: 1
147+ providers:
148+ - name: 'default'
149+ orgId: 1
150+ folder: ''
151+ type: file
152+ options:
153+ path: /var/lib/grafana/dashboards
154+ backup : false
155+ owner : root
156+ group : grafana
157+ mode : 0640
158+ notify : restart grafana
159+ when : grafana_use_provisioning
160+
161+ - name : Import grafana dashboards through provisioning
162+ synchronize :
163+ src : " /tmp/dashboards/"
164+ dest : " /var/lib/grafana/dashboards"
165+ archive : false
166+ checksum : true
167+ recursive : true
168+ delete : " {{ grafana_provisioning_synced }}"
169+ rsync_opts :
170+ - " --no-motd"
171+ when : grafana_use_provisioning
172+ notify : " provisioned dashboards changed"
Original file line number Diff line number Diff line change 7979 find :
8080 paths : " {{ grafana_dashboards_dir }}"
8181 patterns : ' *.json'
82- register : found_dashboards
8382 delegate_to : localhost
8483 run_once : true
84+ register : found_dashboards
85+ tags :
86+ - grafana_configure
87+ - grafana_dashboards
8588
8689- include : dashboards.yml
8790 when : grafana_dashboards | length > 0 or found_dashboards.matched > 0
You can’t perform that action at this time.
0 commit comments