Reputation: 29
curl 'http://admin:[email protected]:3000/api/datasources' -X POST -H 'Content-Type: application/json;charset=UTF-8' --data-binary '{"name":"influx","type":"influxdb","url":"http://localhost:8086","access":"proxy","isDefault":true,"database":"collectd_db","user":"admin","password":"admin"}'
Not sure how to encode this in the ansible uri module. So far I have got this:
- name: next add the database to the grafana
uri:
url: "http://admin:[email protected]:3000/api/datasources"
method: POST
user: admin
password: admin
body: '{"name":"influx","type":"influxdb","url":"http://localhost:8086","access":"proxy","isDefault":true,"database":""{{ influxdb_database|default(collectd_db) }}"","user":"admin","password":"admin"}'
body_format: raw
# force_basic_auth: yes
But it does not work and gives following error:
"msg": "Status code was not [200]: Request failed: <urlopen error [Errno -2] Name or service not known>",
"redirected": false,
"status": -1,
"url": "http://********:********@127.0.0.1:3000/api/datasources"
}
Upvotes: 2
Views: 6589
Reputation:
You can paste your command into curlconverter.com/ansible and it'll convert it to this:
-
name: 'http://127.0.0.1:3000/api/datasources'
uri:
url: 'http://127.0.0.1:3000/api/datasources'
method: POST
body:
name: influx
type: influxdb
url: 'http://localhost:8086'
access: proxy
isDefault: true
database: collectd_db
user: admin
password: admin
body_format: json
headers:
Content-Type: application/json;charset=UTF-8
url_username: admin
url_password: admin
register: result
Upvotes: 0
Reputation: 301
body_format
to json
.body
."{{ influxdb_database|default(collectd_db) }}"
admin:admin@
from url:
value (it's already set through user
and password
).Let us know how you get on after that!
Upvotes: 3
Reputation: 11
I had to resort to the 'command' module
- name: Add graphite datasource
command: >
curl 'http://admin:admin@{{ inventory_hostname }}:3000/api/datasources' -X POST -H 'Content-Type: application/json;charset=UTF-8' --data-binary '{"name":"Graphite Live","type":"graphite","url":"http://graphiteserver.foo.bar","access":"direct","isDefault":true,"database":"asd"}'
Upvotes: 1