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"}'
不确定如何在 ansible uri 模块中对此进行编码。到目前为止我已经得到了这个:
- 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
但它不起作用并给出以下错误:
"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"
}
body_format
设置为 json
。body
之前多余的压痕。"{{ influxdb_database|default(collectd_db) }}"
admin:admin@
值中删除 url:
(已通过 user
和 password
设置)。让我们知道您之后的进展如何!
我不得不求助于“命令”模块
- 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"}'
您可以将命令粘贴到 curlconverter.com/ansible,它会将其转换为:
-
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