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?
2 Answers 2
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'"
3 Comments
and logic, is literally and, not AND. glad you figured it out. just though you should know ;)do-until loop for the same problem above? say loop will be infinitely check this condition "'{{ (response.content | from_json).Requests.request_status }}' != 'PENDING' and '{{ (response.content | from_json).Requests.request_status }}' != 'IN_PROGRESS'".Then on condition met it will come out from the loop. Kindly advice me for the same.It's possible (at least with Ansible 2.8.3) to pass arrays to until:
- shell: "echo OK"
 until:
 - 1 == 1
 - "'no'.replace('no', 'yes') == 'yes'"
In this case array items are implicitly "joined" with and
Comments
Explore related questions
See similar questions with these tags.