I am trying to run an ansible "uri" task that fetches the status in an "until" loop till the status returned is either SUCCESS or FAILED. My task looks like this:
- name: Fetching recycle status
uri:
url: "http://{{ restarter }}/status?job_id={{ item }}"
method: GET
body_format: json
headers:
Accept: 'application/json'
return_content: yes
register: restart_status
with_items:
- 14502414
- 14552415
until: (restart_status.results|json_query('[*].json')| json_query('[*][*].status')|flatten) in ['SUCCESS', 'FAILED']
restart_status is a variable that contains the json payload that is returned and it looks like this:
{
"changed": false,
"results": [
{
"_ansible_ignore_errors": null,
"item": 14502414,
"json": [
{
"created_date": 1635348569000,
"job": {
"application_name": "testapp",
"id": 14552414,
"user": "gui"
},
"status": "FAILED"
}
],
"vary": "Accept-Encoding"
},
{
"_ansible_ignore_errors": null,
"item": 14552415,
"json": [
{
"created_date": 1635348569000,
"job": {
"application_name": "testapp",
"id": 14502415,
"user": "gui"
},
"status": "FAILED"
}
],
"vary": "Accept-Encoding"
}
]
}
The output of (restart_status.results|json_query('[].json')| json_query('[][*].status')|flatten) is
ok: [localhost] => {
"msg": [
"FAILED",
"FAILED"
]
}
I somehow cant seem to get the until clause to work.I have tried multiple things like "contain", "in" ,"not in", ==, but none of it is working. This is the error that is thrown.
TASK [Fetching recycle status] **************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The conditional check '(restart_status.results|json_query('[*].json')| json_query('[*][*].status')|flatten) not in ['INIT', 'PROGRESS']' failed. The error was: Unexpected templating type error occurred on ({% if (restart_status.results|json_query('[*].json')| json_query('[*][*].status')|flatten) not in ['INIT', 'PROGRESS'] %} True {% else %} False {% endif %}): 'NoneType' object is not iterable"}
Any help or pointer to what I am doing wrong is greatly appreciated.