Write data with a PUT request with Ansible URI module

坚强是说给别人听的谎言 提交于 2021-01-28 04:53:41

问题


I'm just trying to translate this cURL call to ansible playbook.

  • cURL call:

    curl -X PUT -d "value={aa}" "http://172.31.64.174:2379/v2/keys/coreos.com/network/config"
    
  • Ansible playbook:

    - uri:
        url: "http://172.31.64.174:2379/v2/keys/coreos.com/network/config"
        method: PUT
        body: "value={aa}"
    

I tried this one but server receive the PUT petition but value is not changed.

This is the verbose output from the cURL procedure:

*   Trying 172.31.64.174...
* Connected to 172.31.64.174 (172.31.64.174) port 2379 (#0)
> PUT /v2/keys/coreos.com/network/config HTTP/1.1
> Host: 172.31.64.174:2379
> User-Agent: curl/7.47.1
> Accept: */*
> Content-Length: 10
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 10 out of 10 bytes
< HTTP/1.1 200 OK
< Content-Type: application/json
< X-Etcd-Cluster-Id: 1dd872ea8ead78
< X-Etcd-Index: 325563
< X-Raft-Index: 1356544
< X-Raft-Term: 2694
< Date: Mon, 21 Mar 2016 08:48:33 GMT
< Content-Length: 228
< 
{"action":"set","node":{"key":"/coreos.com/network/config","value":"{aa}","modifiedIndex":325563,"createdIndex":325563},"prevNode"{"key":"/coreos.com/network/config","value":"{a}","modifiedIndex":324785,"createdIndex":324785}}
* Connection #0 to host 172.31.64.174 left intact

Any help is much appreciated.

Thanks in advance


回答1:


Finally I got it working by setting the status code, the header's content type and the return content by adding these lines:

status_code: 200
return_content: yes
HEADER_Content-Type: "application/x-www-form-urlencoded"

So the final must look like:

- uri:
    url: "{{ etcd_server }}/v2/keys/coreos.com/network/config"
    method: PUT
    body: "value={aa}"
    status_code: 200
    return_content: yes
    HEADER_Content-Type: "application/x-www-form-urlencoded"


来源:https://stackoverflow.com/questions/36126472/write-data-with-a-put-request-with-ansible-uri-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!