来自REST的Ansible Grab Response Headers

时间:2016-08-15 07:55:07

标签: rest ansible ansible-playbook

我正在编写一个可以进行REST调用的ansible playbook,并且调用返回一个location标题,我需要在代码中抓取并进一步使用它。

我知道我可以使用变量,但它们似乎无法正常工作。

这是我的剧本以及-v旗帜的执行结果。我如何使这个工作?

我已尝试locationresponse.locationheaders.location& resp

ansible_REST_deployment

1 个答案:

答案 0 :(得分:1)

您应该尝试打印您收到的回复。这是我试过的:

 - hosts: localhost
   become: yes
   tasks:
   - uri:
       url: http://httpstat.us/301
       method: GET
     register: resp
   - debug: msg="{{ resp }}"

第二个任务将resp的值打印为:

    "msg": {
    "access_control_allow_origin": "*",
    "cache_control": "private",
    "changed": false,
    "connection": "close",
    "content_length": "6971",
    "content_type": "text/html; charset=utf-8",
    "date": "Mon, 15 Aug 2016 14:33:37 GMT",
    "msg": "OK (6971 bytes)",
    "redirected": true,
    "server": "Microsoft-IIS/8.0",
    "set_cookie": "ARRAffinity=0fa2349d7a572a87201de50cff098b071ad26e41abdb03b66af86cc85cf7f658;Path=/;Domain=httpstat.us",
    "status": 200,
    "url": "http://httpstat.us/",
    "via": "1.1 rtp10-dmz-wsa-2.cisco.com:80 (Cisco-WSA/9.0.1-162)",
    "x_aspnet_version": "4.0.30319",
    "x_aspnetmvc_version": "5.1",
    "x_powered_by": "ASP.NET"
}
您正在寻找

网址字段。