ansible uri相当于curl命令

时间:2017-07-05 14:45:03

标签: curl ansible uri grafana

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"

}

2 个答案:

答案 0 :(得分:1)

  1. 尝试将body_format设为json
  2. 删除body之前的多余缩进。
  3. 删除"{{ influxdb_database|default(collectd_db) }}"
  4. 周围多余的双引号
  5. admin:admin@值中删除url:(已经设置userpassword)。
  6. 让我们知道你之后如何继续!

答案 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"}'