tur*_*enh 4 python yaml jinja2 ansible ansible-2.x
我正在进行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
Run Code Online (Sandbox Code Playgroud)
错误是:
"条件检查''{{(response.content | from_json).Requests.request_status}}'!='PENDING'和'{{(response.content | from_json).Requests.request_status}}'!='IN_PROGRESS' '失败.错误是:模板错误,模板字符串:期望令牌'结束语句块',得到'AND'.字符串:{%if'COMPLETED'!='PENDING'和'COMPLETED'!='IN_PROGRESS'% }真{%else%} False {%endif%}"
所以,我的问题是如何在Ansible的do-until循环中指定多个条件?
好的发现了问题.
将"AND"改为"和"工作.
直到:"'{{(response.content | from_json).Requests.request_status}}'!='PENDING' 和 '{{(response.content | from_json).Requests.request_status}}'!='IN_PROGRESS'"
可以(至少在 Ansible 2.8.3 中)将数组传递给until:
- shell: "echo OK"
until:
- 1 == 1
- "'no'.replace('no', 'yes') == 'yes'"
Run Code Online (Sandbox Code Playgroud)
在这种情况下,数组项隐式“连接”为and
| 归档时间: |
|
| 查看次数: |
3197 次 |
| 最近记录: |