Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify multiple conditions in a do-until loop in Ansible

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?

like image 853
turkenh Avatar asked Dec 15 '22 06:12

turkenh


1 Answers

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

like image 77
turkenh Avatar answered Dec 16 '22 20:12

turkenh