6

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?

asked Apr 26, 2016 at 19:42

2 Answers 2

9

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'"

answered Apr 26, 2016 at 20:09
Sign up to request clarification or add additional context in comments.

3 Comments

when you are using Jinja, you are actually executing python. the proper python vernacular for the and logic, is literally and, not AND. glad you figured it out. just though you should know ;)
Can we create an infinite loop without 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.
how annoying. The error messages are treasurehunts anyways in Ansible.
7

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

answered Oct 17, 2019 at 13:17

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.