curl 'http://admin:admin@127.0.0.1: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"}'
不确定如何在ansible uri模块中对此进行编码。到目前为止,我已经得到了这个:
- name: next add the database to the grafana
uri:
url: "http://admin:admin@127.0.0.1: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
但它不起作用,并给出以下错误:
"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"
}
答案 0 :(得分:1)
body_format
设为json
。body
之前的多余缩进。"{{ influxdb_database|default(collectd_db) }}"
admin:admin@
值中删除url:
(已经设置user
和password
)。让我们知道你之后如何继续!
答案 1 :(得分:0)
我不得不求助于&#39;命令&#39;模块
- 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"}'