rest - Ansible 从 REST 获取响应 header

标签 rest ansible

我正在编写一个 ansible playbook,它进行 REST 调用,并且该调用返回一个 location header ,我需要在代码中进一步获取和使用该 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 字段就是您要查找的内容。

关于rest - Ansible 从 REST 获取响应 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38951297/

相关文章:

ubuntu - 可靠的 : How to handle first login forced password change and push an ssh-key

rest - 如何从 postman 中访问部署在云中的http服务?

c# - Azure 表存储 - 通过分区键删除实体 REST API

javascript - 使用loopback.io创建一个新项目

python - 如何对同一模型使用两个不同的模型序列化程序?

Ansible:使用 Ansible 使用 Diff 命令

python - Ansible azure_rm_virtualmachine 在 Mac 上因缺少 pip 包而失败

Ansible 成为密码

java - 构建休息服务器

macos - 在 OSX 上安装 Ansible