|
1 | 1 | --- |
2 | | -- block: |
3 | | - - name: Check datasources list (api) |
4 | | - uri: |
5 | | - url: "{{ grafana_api_url }}/api/datasources" |
6 | | - user: "{{ grafana_security.admin_user }}" |
7 | | - password: "{{ grafana_security.admin_password }}" |
8 | | - force_basic_auth: true |
9 | | - return_content: true |
10 | | - no_log: true |
11 | | - register: datasources |
12 | | - |
13 | | - - name: Create grafana datasources (api) |
14 | | - uri: |
15 | | - url: "{{ grafana_api_url }}/api/datasources" |
16 | | - user: "{{ grafana_security.admin_user }}" |
17 | | - password: "{{ grafana_security.admin_password }}" |
18 | | - force_basic_auth: true |
19 | | - method: POST |
20 | | - body_format: json |
21 | | - body: "{{ item | to_json }}" |
22 | | - with_items: "{{ grafana_datasources }}" |
23 | | - no_log: true |
24 | | - when: ((datasources['json'] | selectattr("name", "equalto", item['name'])) | list) | length == 0 |
25 | | - |
26 | | - - name: Update grafana datasources (api) |
27 | | - uri: |
28 | | - url: "{{ grafana_api_url }}/api/datasources/{{ ( |
29 | | - datasources['json'] | |
30 | | - selectattr('name', 'equalto', item['name']) | |
31 | | - map(attribute='id') | |
32 | | - unique | |
33 | | - join() |
34 | | - ) }}" |
35 | | - user: "{{ grafana_security.admin_user }}" |
36 | | - password: "{{ grafana_security.admin_password }}" |
37 | | - force_basic_auth: true |
38 | | - method: PUT |
39 | | - body_format: json |
40 | | - body: "{{ item | to_json }}" |
41 | | - with_items: "{{ grafana_datasources }}" |
42 | | - no_log: true |
43 | | - when: ((datasources['json'] | selectattr("name", "equalto", item['name'])) | list) | length != 0 |
| 2 | +- name: Ensure datasources exist (via API) |
| 3 | + grafana_datasource: |
| 4 | + grafana_url: "{{ grafana_api_url }}" |
| 5 | + grafana_user: "{{ grafana_security.admin_user }}" |
| 6 | + grafana_password: "{{ grafana_security.admin_password }}" |
| 7 | + name: "{{ item.name }}" |
| 8 | + url: "{{ item.url }}" |
| 9 | + ds_type: "{{ item.type }}" |
| 10 | + access: "{{ item.access | default(omit) }}" |
| 11 | + is_default: "{{ item.isDefault | default(omit) }}" |
| 12 | + basic_auth_user: "{{ item.basicAuthUser | default(omit) }}" |
| 13 | + basic_auth_password: "{{ item.basicAuthPassword | default(omit) }}" |
| 14 | + with_items: "{{ grafana_datasources }}" |
44 | 15 | when: not grafana_use_provisioning |
45 | 16 |
|
46 | 17 | - name: Create/Update datasources file (provisioning) |
|
0 commit comments