检查哪些主机在 ansible 中失败了剧本 [英] Checking which hosts failed a playbook in ansible
问题描述
我有 2 个剧本在 ansible 上运行,一个接一个.剧本 1 完成后,我想仅在第一个剧本完全成功的主机上运行第二个剧本.查看 ansible 文档,我找不到有关哪些主机使特定剧本失败的任何可访问信息.这怎么可能?
I have 2 playbooks running on ansible, one after another. After playbook 1 finishes, I want to run the second one on only the hosts for which the first playbook fully succeeded. Looking through the ansible docs, I can't find any accessible info on which hosts failed a specific playbook. How could this be done?
仅供参考,我需要单独的剧本,因为第二本必须串行运行,仅在剧本级别可用
FYI I need separate playbooks because the second one must be run with in serial, which is only available at the playbook level
推荐答案
其中all hosts - success hosts = failed hosts
,可以通过下面的任务得到两个特殊变量的区别播放中的所有主机(包括故障主机)和所有尚未故障的主机.使用serial
会影响结果.
Where all hosts - successful hosts = failed hosts
, you can use the following task to get the difference between the two special variables for all hosts in the play (including failed hosts) and all hosts that have not yet failed. Use of serial
will affect the result.
- name: Print play hosts that failed
debug:
msg: "The hosts that failed are {{ ansible_play_hosts_all| difference(ansible_play_batch) |join('\n') }}"
来源:https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html
这篇关于检查哪些主机在 ansible 中失败了剧本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!