在阅读文档之后,似乎ansible不支持do_until用于块中的多个任务以及include_task。我的用例是在一个安静的URL上做一个帖子,然后获得该restful响应的状态并继续这样做。为简洁起见,宁静的回应有两个属性状态和progess。轮询和重试一个属性很容易,但如何显示progess?
- name: get command {{ command_id }} status
uri:
url: "myrestfulurl/status/{{ command_id }}"
method: GET
user: "foo"
password: "bar"
body_format: json
validate_certs: no
force_basic_auth: yes
return_content: yes
headers:
X-Requested-By: foo
register: rest_response
until: rest_response.content | from_json | json_query('Requests.request_status') == "IN_PROGRESS"
retries: 3
progess可以报告如下
progress: "{{ rest_response.content | from_json | json_query('Requests.progress_percent') }}"
我怎样才能在任务的名称部分说出这一点。请注意,第一次注册的响应不可用?
例如
- name: get command {{ command_id }} status {{ { rest_response.content is defined | ternary( ... ) }} ?
也试图这样做
- set_fact:
temp: "{\"Requests\" : {\"request_status\" : \"COMPLETED\" } }"
- debug:
msg: "{{ temp | from_json | json_query('Requests.request_status')}}"
- name: get command {{ command_id }} status {{ rest_response.content | default(temp) | from_json | json_query('Requests.request_status') }}
导致以下结果;价值未得到解决
FAILED - RETRYING: get command {{ command_id }} status {{ rest_response.content | default(temp) | from_json | json_query('Requests.request_status') }} (3 retries left).
FAILED - RETRYING: get command {{ command_id }} status {{ rest_response.content | default(temp) | from_json | json_query('Requests.request_status') }} (2 retries left).
FAILED - RETRYING: get command {{ command_id }} status {{ rest_response.content | default(temp) | from_json | json_query('Requests.request_status') }} (1 retries left).
注意;我有我的进步并完全逆转进行测试;希望这不会让任何人失望。