6

我正在进行 REST 调用,并希望在继续之前检查我的请求是否已完成。在响应中,我得到一个“PENDING”或“IN_PROGRESS”作为 request_status。我想等到我得到“完成”或“失败”。为此,我想等待“PENDING”或“IN_PROGRESS”

我尝试了很多变化但未能成功,最后一次尝试如下:

  - 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

错误是:

“条件检查 ''{{ (response.content | from_json).Requests.request_status }}' != 'PENDING' AND '{{ (response.content | from_json).Requests.request_status }}' != 'IN_PROGRESS' '失败。错误是:模板化字符串时出现模板错误:预期标记'语句块结束',得到'AND'。字符串:{% if 'COMPLETED' != 'PENDING' AND 'COMPLETED' != 'IN_PROGRESS' % } 真 {% else %} 假 {% endif %}"

所以,我的问题是如何在 Ansible 的 do-until 循环中指定多个条件?

4

2 回答 2

8

好的,发现了问题。

将“AND”更改为“and”有效。

直到:“'{{ (response.content | from_json).Requests.request_status }}' != 'PENDING' and '{{ (response.content | from_json).Requests.request_status }}' != 'IN_PROGRESS'”

于 2016-04-26T20:09:56.433 回答
5

可以(至少在 Ansible 2.8.3 中)将数组传递给until

- shell: "echo OK"
  until:
    - 1 == 1
    - "'no'.replace('no', 'yes') == 'yes'"

在这种情况下,数组项被隐式“加入”and

于 2019-10-17T13:17:42.540 回答