使用Ansible URI模块通过PUT请求写入数据 [英] Write data with a PUT request with Ansible URI module
本文介绍了使用Ansible URI模块通过PUT请求写入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想将此cURL调用转换为可播放的剧本.
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 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屋!
查看全文