Hello,
I have a Grafana installation and I would like to query the HTTP API and
then compare the data sources on the server to a dict for the data
sources. If one of the data sources in the dictionary is new I would
like to create it (later I will work on changing).
I'm thing that I need to do some type of nested loop but, can't seem to
figure it out.
Any help would be very much appreciated.
Thanks,
Hank
This is what I have in the dictionary:
- debug: var=grafana_ds
TASK: [grafana | debug var=grafana_ds]
****************************************
<some_server> ESTABLISH CONNECTION FOR USER: ansible
ok: [some_server] => {
"var": {
"grafana_ds": {
"cache_stats": {
"access": "direct",
"basicAuth": false,
"basicAuthPassword": "password",
"basicAuthUser": "user",
"database": "cache_stats",
"isDefault": false,
"jsonData": null,
"password": "password",
"type": "influxdb",
"url": "https://some_other_server",
"user": "user"
},
"deliveryservice_stats": {
"access": "direct",
"basicAuth": false,
"basicAuthPassword": "basicpassword",
"basicAuthUser": "basicuser",
"database": "deliveryservice_stats",
"isDefault": false,
"jsonData": null,
"password": "password",
"type": "influxdb",
"url": "https://some_other_server",
"user": "user"
},
"test_stats": {
"access": "direct",
"basicAuth": false,
"basicAuthPassword": "basicpassword",
"basicAuthUser": "basicuser",
"database": "test_stats",
"isDefault": false,
"jsonData": null,
"password": "password",
"type": "influxdb",
"url": "https://some_other_server",
"user": "user"
}
}
}
}
This is what the HTTP API Returns:
- name: Get a list of Data Sources
uri:
url: https://{{ inventory_hostname }}/api/datasources
return_content: yes
method: GET
HEADER_Authorization: Bearer {{grafana_api_key}}
HEADER_Accept: application/json
HEADER_Content-Type: application/json
validate_certs: no
register: playbook_grafana_ds
TASK: [grafana | debug var=playbook_grafana_ds.json]
**************************
<some_server> ESTABLISH CONNECTION FOR USER: ansible
ok: [some_server] => {
"var": {
"playbook_grafana_ds.json": [
{
"access": "direct",
"basicAuth": false,
"basicAuthPassword": "",
"basicAuthUser": "",
"database": "cache_stats",
"id": 1,
"isDefault": false,
"jsonData": null,
"name": "cache_stats",
"orgId": 1,
"password": "password",
"type": "influxdb",
"url": "https://some_other_server",
"user": "user"
},
{
"access": "direct",
"basicAuth": false,
"basicAuthPassword": "",
"basicAuthUser": "",
"database": "deliveryservice_stats",
"id": 2,
"isDefault": false,
"jsonData": null,
"name": "deliveryservice_stats",
"orgId": 1,
"password": "password",
"type": "influxdb",
"url": "https://some_other_server",
"user": "user"
}
]
}
}
Here is the start of the task that I'm trying to accomplish but, doesn't
even come close to working:
- name: Create Data Sources
uri:
url: https://{{ inventory_hostname }}/api/datasources
return_content: yes
method: POST
HEADER_Authorization: Bearer {{grafana_api_key}}
HEADER_Accept: application/json
HEADER_Content-Type: application/json
body: "{{ lookup('template','../templates/datasources.json.j2') }}"
validate_certs: no
when: item.key not in playbook_grafana_ds.json
with_dict: grafana_ds
--
You received this message because you are subscribed to the Google Groups "Ansible
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/55FAC390.9090308%40gmail.com.
For more options, visit https://groups.google.com/d/optout.