Loop until with delay: {{ variable.json.counter}}

Hi.

I’m running my playbook to get akamai to clear some caches and I’m using theit REST API that return json.

now I’m running into a problem with a look that I want to delay for X amount of seconds and X is part of the json response from the api so I’m doing something like :

  • name: Wait for akamai to clear
    action: uri url=https://api.ccu.akamai.com{{akamairesponse.json.progressUri}}
    method=GET user=xxx password=xxx
    HEADER_Content-Type=“application/json”
    status_code=200
    return_content=yes
    register: akamaistatus
    #- debug: msg=“value of status {{akamaistatus.json.purgeStatus}}”
    until: “‘{{akamaistatus.json.purgeStatus}}’ == ‘Done’”
    retries: 10
    #delay: 60
    delay: ‘{{akamairesponse.json.estimatedSeconds|int}}’

debug shows :

TASK: [debug msg=“value of {{akamairesponse.json.estimatedSeconds|int}}”] *****
ok: [localhost] => {
“msg”: “value of 420”
}

but when I run the playbook I get this :

TASK: [Wait for akamai to clear] **********************************************
EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-1385160064.24-173468909890043 && chmod a+rx $HOME/.ansible/tmp/ansible-1385160064.24-173468909890043 && echo $HOME/.ansible/tmp/ansible-1385160064.24-173468909890043’]
REMOTE_MODULE uri url=https://api.ccu.akamai.com/ccu/v2/purges/ef63d1a5-5401-11e3-8c54-712f0c54712f method=GET user=xxx password=xxx HEADER_Content-Type=“application/json” status_code=200 return_content=yes
PUT /tmp/tmpctvzt8 TO /usr/home/jamengual/.ansible/tmp/ansible-1385160064.24-173468909890043/uri
EXEC [‘/bin/sh’, ‘-c’, ‘/usr/local/bin/python /usr/home/jamengual/.ansible/tmp/ansible-1385160064.24-173468909890043/uri; rm -rf /usr/home/jamengual/.ansible/tmp/ansible-1385160064.24-173468909890043/ >/dev/null 2>&1’]
fatal: [localhost] => Traceback (most recent call last):
File “/usr/local/lib/python2.7/site-packages/ansible/runner/init.py”, line 394, in _executor
exec_rc = self._executor_internal(host, new_stdin)
File “/usr/local/lib/python2.7/site-packages/ansible/runner/init.py”, line 485, in _executor_internal
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
File “/usr/local/lib/python2.7/site-packages/ansible/runner/init.py”, line 688, in _executor_internal_inner
time.sleep(delay)
TypeError: a float is required

FATAL: all hosts have already failed – aborting

I tried using jinga2 filter as float and int and it doesn’t work is there a limitation with loops delay variables ?

Thanks.

Hello,

I think this case was not coded in the handling of delay.
example:

delay: 60

=> ok

delay: “60”

=>TypeError: a float is required

delay: !!float “60”

=> ok

unfortunately the YAML cast cannot work in your case since yaml will complain that your string cannot be cast to float.

maybe others can confirm

Hi guys,

Bugs get filed on github, not the mailing list.

Thanks!

you seem to confirm this is a bug
bug filed : https://github.com/ansible/ansible/issues/5031

thanks

Well I didn’t know that was a bug :)…until now.