使用Ansible URI模块

时间:2016-03-21 08:51:37

标签: curl ansible ansible-playbook ansible-2.x

我只是想把这个cURL调用转换成ansible playbook。

  • cURL电话:

    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申请,但价值没有改变。

这是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

非常感谢任何帮助。

提前致谢

1 个答案:

答案 0 :(得分:1)

最后,我通过添加这些行设置状态代码,标题的内容类型和返回内容来实现它:

- 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"

所以决赛必须如下:

.run(function ($ionicPlatform, $http) {
    $ionicPlatform.ready(function () {
        var push = new Ionic.Push({
            "debug": true,
            "pluginConfig": {
                "android": {
                    "icon": "ic_stat_icon"
                }
            }
        });

        push.register(function(token) {
            console.log("Device token: " + token.token);
        })
    });
})