来自 REST 的 Ansible Grab 响应 Headers

Ansible Grab Response Headers from REST

我正在编写一个 ansible 剧本,它进行 REST 调用和调用 returns a location header,我需要在代码中进一步获取和使用它。

我知道我可以为此使用变量,但它们似乎不起作用。

这是我的剧本和使用 -v 标志执行的结果。我如何让它工作?

我试过 locationresponse.locationheaders.locationresp

ansible_REST_deployment

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

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

URL 字段就是您要查找的内容。