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
15
15
- Ansible >= 2.5
16
16
- libselinux-python on deployer host (only when deployer machine has SELinux)
17
17
- 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
18
19
19
20
## Role Variables
20
21
21
22
All variables which can be overridden are stored in [ defaults/main.yml] ( defaults/main.yml ) file as well as in table below.
22
23
23
24
| Name | Default Value | Description |
24
25
| -------------- | ------------- | -----------------------------------|
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. |
26
28
| ` grafana_system_user ` | grafana | Grafana server system user |
27
29
| ` grafana_system_group ` | grafana | Grafana server system group |
28
30
| ` 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
5
5
# Should we use the provisioning capability when possible (provisioning require grafana >= 5.0)
6
6
grafana_use_provisioning : true
7
7
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
+
8
11
grafana_instance : " {{ ansible_fqdn | default(ansible_host) | default(inventory_hostname) }}"
9
12
10
13
grafana_logs_dir : " /var/log/grafana"
Original file line number Diff line number Diff line change 4
4
service :
5
5
name : grafana-server
6
6
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 2
2
- name : Prepare
3
3
hosts : all
4
4
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 1
1
---
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
+
2
13
- name : Create local grafana dashboard directories
3
14
become : false
4
15
file :
8
19
delegate_to : localhost
9
20
run_once : true
10
21
check_mode : false
22
+ changed_when : false
11
23
12
24
# - name: download grafana dashboard from grafana.net to local folder
13
25
# become: false
96
108
- " {{ grafana_dashboards_dir }}/*.json"
97
109
delegate_to : localhost
98
110
run_once : true
111
+ changed_when : false
99
112
100
- - name : import grafana dashboards
113
+ - name : import grafana dashboards through API
101
114
uri :
102
115
url : " {{ grafana_api_url }}/api/dashboards/db"
103
116
user : " {{ grafana_security.admin_user }}"
109
122
no_log : true
110
123
with_fileglob :
111
124
- " /tmp/dashboards/*"
125
+ when : not grafana_use_provisioning
112
126
113
127
# TODO: uncomment this when ansible 2.7 will be min supported version
114
128
# - name: import grafana dashboards
123
137
# no_log: true
124
138
# with_fileglob:
125
139
# - "/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 79
79
find :
80
80
paths : " {{ grafana_dashboards_dir }}"
81
81
patterns : ' *.json'
82
- register : found_dashboards
83
82
delegate_to : localhost
84
83
run_once : true
84
+ register : found_dashboards
85
+ tags :
86
+ - grafana_configure
87
+ - grafana_dashboards
85
88
86
89
- include : dashboards.yml
87
90
when : grafana_dashboards | length > 0 or found_dashboards.matched > 0
You can’t perform that action at this time.
0 commit comments