What is the debug output of just {{akamairesponse}} and
{{akamairesponse.content}} ? Just trying to narrow down...


On Thu, Nov 21, 2013 at 8:31 AM, PePe Amengual <[email protected]>wrote:

> This is what I get from the API :
>
>
> HTTP/1.1 201 Created
> Date: Thu, 21 Nov 2013 18:01:08 GMT
> Server: Apache
> Content-Length: 268
> Content-Location: /ccu/v2/purges/e771b867-52d6-11e3-bcaf-2a98bcaf2a98
> Allow: GET, HEAD, POST
> Vary: Authorization
> Content-Type: application/json
>
> {"estimatedSeconds": 420, "progressUri":
> "/ccu/v2/purges/e771b867-52d6-11e3-bcaf-2a98bcaf2a98", "purgeId":
> "e771b867-52d6-11e3-bcaf-2a98bcaf2a98", "supportId":
> "17PY1385056868737216-189879392", "httpStatus": 201, "detail": "Request
> accepted.", "pingAfterSeconds": 420}⏎
>
> my uri request from the playbook :
>
> tasks:
>    - name: Flushing Akamai cache
>      action: uri url=https://api.ccu.akamai.com/ccu/v2/queues/default
>              method=POST user=aaaa password=aaaa
>              HEADER_Content-Type="application/json"
>              body='{"objects":["{{urllist}}"]}'
>              status_code=201
>              return_content=yes
>      register: akamairesponse
>    - debug: msg="value of {{akamairesponse.content.purgeId}}"
>    - name: Notifing
>      action: hipchat token=aaa room=Akamai msg="Purged {{urllist}}"
>      action: hipchat token=aaa room=Akamai
> msg="{{akamairesponse.content.purgerId}}"
>
> I get in hipchat this {{akamairesponse.content.purgerId}} like a string is
> not actually parsing the data.
>
> the debug :
>
> PLAY [localhost]
> **************************************************************
>
> TASK: [Flushing Akamai cache]
> *************************************************
> <localhost> EXEC ['/bin/sh', '-c', 'mkdir -p
> $HOME/.ansible/tmp/ansible-1385033255.71-37626758703564 && chmod a+rx
> $HOME/.ansible/tmp/ansible-1385033255.71-37626758703564 && echo
> $HOME/.ansible/tmp/ansible-1385033255.71-37626758703564']
> <localhost> REMOTE_MODULE uri url=
> https://api.ccu.akamai.com/ccu/v2/queues/default method=POST user=xxxxxx
> password=xxxxx HEADER_Content-Type="application/json" body='{"objects":["
> http://xxxx/images/flags/uk.png"]}' status_code=201 return_content=yes
> <localhost> PUT /tmp/tmpR6pSOQ TO
> /usr/home/jamengual/.ansible/tmp/ansible-1385033255.71-37626758703564/uri
> <localhost> EXEC ['/bin/sh', '-c', '/usr/local/bin/python
> /usr/home/jamengual/.ansible/tmp/ansible-1385033255.71-37626758703564/uri;
> rm -rf
> /usr/home/jamengual/.ansible/tmp/ansible-1385033255.71-37626758703564/
> >/dev/null 2>&1']
> ok: [localhost] => {"allow": "GET, HEAD, POST", "changed": false,
> "content": "{\"estimatedSeconds\": 420, \"progressUri\":
> \"/ccu/v2/purges/bcb3d980-52da-11e3-b16b-21bd716b21bd\", \"purgeId\":
> \"bcb3d980-52da-11e3-b16b-21bd716b21bd\", \"supportId\":
> \"17PY1385058515823533-206664800\", \"httpStatus\": 201, \"detail\":
> \"Request accepted.\", \"pingAfterSeconds\": 420}", "content_length":
> "268", "content_location":
> "/ccu/v2/purges/bcb3d980-52da-11e3-b16b-21bd716b21bd", "content_type":
> "application/json", "date": "Thu, 21 Nov 2013 18:28:35 GMT", "json":
> {"detail": "Request accepted.", "estimatedSeconds": 420, "httpStatus": 201,
> "pingAfterSeconds": 420, "progressUri":
> "/ccu/v2/purges/bcb3d980-52da-11e3-b16b-21bd716b21bd", "purgeId":
> "bcb3d980-52da-11e3-b16b-21bd716b21bd", "supportId":
> "17PY1385058515823533-206664800"}, "redirected": false, "server": "Apache",
> "status": "201", "vary": "Authorization"}
>
> TASK: [debug msg="value of {{akamairesponse.content.purgeId}}"]
> ***************
> fatal: [localhost] => One or more undefined variables: 'unicode object'
> has no attribute 'purgeId'
>
> FATAL: all hosts have already failed -- aborting
>
> PLAY RECAP
> ********************************************************************
>            to retry, use: --limit @/usr/home/jamengual/akamai.retry
>
> localhost                  : ok=1    changed=0    unreachable=1
>  failed=0
>
> I tried with : {{akamairesponse.content.purgeId}} and
> {{akamairesponse.content.[purgeId]}},
> {{akamairesponse.content.["purgeId"]}} and
> {{akamairesponse.content."purgeId"}} and it doesn't work.
>
> am I doing something wrong ?
>
> Thanks.
>
> On Thursday, 21 November 2013 02:44:35 UTC, Romeo Theriault wrote:
>
>> On Wed, Nov 20, 2013 at 2:24 PM, PePe Amengual <[email protected]>wrote:
>>
>>> I'm basically having the same issue I need to get  from this :
>>>
>>> {
>>>    "httpStatus" : 201,
>>>    "detail" : "Request accepted.",
>>>    "estimatedSeconds" : 420,
>>>    "purgeId" : "95b5a092-043f-4af0-843f-aaf0043faaf0",
>>>    "progressUri" : "/ccu/v2/purges/95b5a092-043f-
>>> 4af0-843f-aaf0043faaf0",
>>>    "pingAfterSeconds" : 420,
>>>    "supportId" : "17PY1321286429616716-211907680",
>>> }
>>>
>>> the pingAfterSeconds to use it in a wait_for task and the purgeid but
>>> this is a JSON so dunno if the process is similar to a string parsing?
>>>
>>
>>
>> If the web service returns a Content-type header set as
>> "application/json" and the response you get is valid json then the uri
>> module will parse the JSON and make it available via the key.
>>
>> See https://github.com/ansible/ansible/pull/2119 for more details.
>>
>> So you should be able to do something like {{ 
>> register_var.content.pingAfterSeconds
>> }} to get the value. (Not tested, but you get the idea.)
>>
>> Once you get it, it would be good to send a pull request better
>> documenting this :)
>>
>>
>> --
>> Romeo
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Romeo

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to