2

我只是想把这个 cURL 调用翻译成 ansible playbook。

  • 卷曲调用:

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

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

我试过这个,但服务器收到了 PUT 请愿,但值没有改变。

这是 cURL 过程的详细输出:

*   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

任何帮助深表感谢。

提前致谢

4

1 回答 1

1

最后,我通过添加以下几行来设置状态代码、标题的内容类型和返回内容,使其工作:

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

所以最终必须看起来像:

- 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"
于 2016-03-21T09:01:40.257 回答