I am making a REST call and want to check my request to be completed before going on. In the response, I either got a "PENDING" or "IN_PROGRESS" as request_status. I want to wait until I get either a "COMPLETED" or "FAILED". For this purpose, I want to wait while getting a "PENDING" or "IN_PROGRESS"
I tried lots of variations but could not succeeded and the last try was as below:
- name: Wait for the cluster deployment (this will take a while)
uri:
url: http://localhost:8080/api/v1/clusters/{{ cluster_name }}/requests/1
method: GET
user: admin
password: admin
HEADER_X-Requested-By: Ansible
force_basic_auth: yes
status_code: 200, 201, 202
return_content: yes
register: response
until: "'{{ (response.content | from_json).Requests.request_status }}' != 'PENDING' AND '{{ (response.content | from_json).Requests.request_status }}' != 'IN_PROGRESS'"
retries: 3
delay: 5
And the error is:
"The conditional check ''{{ (response.content | from_json).Requests.request_status }}' != 'PENDING' AND '{{ (response.content | from_json).Requests.request_status }}' != 'IN_PROGRESS'' failed. The error was: template error while templating string: expected token 'end of statement block', got 'AND'. String: {% if 'COMPLETED' != 'PENDING' AND 'COMPLETED' != 'IN_PROGRESS' %} True {% else %} False {% endif %}"
So, my question is how can I specify multiple conditions in a do-until loop in Ansible?
Ok found the problem.
Changing "AND" to "and" worked.
until: "'{{ (response.content | from_json).Requests.request_status }}' != 'PENDING' and '{{ (response.content | from_json).Requests.request_status }}' != 'IN_PROGRESS'"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With