我似乎在meta标记中使用when条件时遇到问题。我尝试了一些变体并且也做了一些阅读,仍然不确定,所以我想我也应该在这里问
任务
- name: "This is my task"
command: "{{ path to conda }} {{ script }}"
register: check
until: check is succeeded
retries: 5
no_log: false
- name: "End this play if the script ran successfully on 1 remote target"
meta: end_play
when:
- check is succeeded
错误
错误!条件检查“检查成功”失败。错误原为:失败的测试需要字典,该错误似乎具有位于'/path/to/roles/tasks/main.yml':第9行第3列,但可能是文件中的其他位置,具体取决于确切的语法问题。的违规行似乎是:-名称:“如果脚本在1个远程目标上成功运行,则结束播放” ^这里
更新(为了完成而共享)
共享规定的解决方法。在我的用例中,我本质上想在整个清单上“尝试”一个任务[[直到]成功最终使用主机变量。如果任务是清单中的第一个主机,它将始终尝试该任务,并在决定在下一个inv主机上再次执行该任务之前,将“回顾”先前的主机。# my task
- name: "Attempt this task on each host if unsuccessful"
raw: "raw_command_here_as_remote_host_is_using_rbash"
register: status
when: >
inventory_hostname == ansible_play_hosts_all[0] or
hostvars [ ansible_play_hosts_all [ groups ['my_host_group'].index(inventory_hostname) | int - 1 ] ] ['stop_it'] == 'false'
ignore_errors: yes
until: status is succeeded
retries: 1
- set_fact:
stop_it: true
cacheable: yes
when: status is succeeded
- set_fact:
stop_it: false
cacheable: yes
when: status is not succeeded
我似乎在meta标记中使用when条件时遇到问题。我已经尝试了一些变体并且也做了一些阅读,仍然不确定,所以我想我也要在这里问。任务-名称:“ This ...
更新(为完成而共享答案)