2016-08-10 38 views
0

目前,我用curl一個HTTP PUT發送到我的API:轉換捲曲API PUT到Ansbile劇本

curl -k -s -u icinga:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/hosts/dbserver.example.com' -d '{ "templates": [ "generic-host" ], "attrs": { "zone": "vienna", "address": "xxx.xx.xx.x", "check_command": "hostalive", "vars.os" : "Linux", "vars.agent" : "ssh" } }' | python -m json.tool 

這就像一個魅力。

我在嘗試將此api調用轉換爲合理的操作手冊。我知道URI提供了URI模塊,所以我試圖使用它,但是可能有些東西配置不正確。

--- 
- name: Add new host 
    uri: 
     url: icinga2.example.com:5665/v1/objects/hosts/client.example.com 
     method: PUT 
     user: admin 
     password: xxxxxxx 
     body: { templates: [ "generic-host" ], attrs: { "zone": "vienna", 
"address": "172.x.x.xx", "check_command": "hostalive", "vars.os" : "Linux", "vars.agent" : "ssh" } } 
     headers: "application/json" 
    register: icinga_log 
    when: inventory_hostname in groups ['vienna'] 
    with_items: "{{ groups['icinga-monitoring'] }}" 
+0

,您應突出與CTRL + K –

+0

代碼會發生什麼事,當你嘗試的例子你有嗎? –

回答

1

通常情況下,您可以按照錯誤信息生成並修復您的語法。
嘗試啓動這個修改:

- name: Add new host 
    uri: 
    url: http://icinga2.example.com:5665/v1/objects/hosts/client.example.com 
    method: PUT 
    user: admin 
    password: xxxxxxx 
    body: '{ templates: [ "generic-host" ], attrs: { "zone": "vienna", "address": "172.x.x.xx", "check_command": "hostalive", "vars.os" : "Linux", "vars.agent" : "ssh" } }' 
    body_format: json 
    headers: 
     Content-Type: application/json