Ian Smith Ian Smith - 3 months ago 24
reST (reStructuredText) Question

Ansible Grab Response Headers from REST

I'm writing an ansible playbook which makes a REST call and the call returns a

location
header which I need to grab and use further on in the code.

I understand that I can use variables for this, but they don't seem to be working.

Here's my playbook and result of execution with the
-v
flag. How do I get this working?

I've tried
location
,
response.location
,
headers.location
&
resp


ansible_REST_deployment

Answer

You should try printing the response you're getting. Here is what I tried:

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

The second tasks prints the value of resp as :

    "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 field is what you're looking for.

Comments