使用带有 Ansible URI 模块的 PUT 请求写入数据 [英] Write data with a PUT request with Ansible URI module
本文介绍了使用带有 Ansible URI 模块的 PUT 请求写入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想把这个 cURL 调用翻译成 ansible playbook.
I'm just trying to translate this cURL call to ansible playbook.
cURL 调用:
cURL call:
curl -X PUT -d "value={aa}" "http://172.31.64.174:2379/v2/keys/coreos.com/network/config"
Ansible 手册:
Ansible playbook:
- uri:
url: "http://172.31.64.174:2379/v2/keys/coreos.com/network/config"
method: PUT
body: "value={aa}"
我试过这个,但服务器收到了 PUT 请求,但值没有改变.
I tried this one but server receive the PUT petition but value is not changed.
这是 cURL 过程的详细输出:
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
非常感谢任何帮助.
提前致谢
推荐答案
最后,我通过添加这些行来设置状态代码、标题的内容类型和返回内容:
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"
这篇关于使用带有 Ansible URI 模块的 PUT 请求写入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文