检查哪个主机在ansible中使剧本失败 [英] Checking which hosts failed a playbook in ansible

查看:55
本文介绍了检查哪个主机在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

推荐答案

其中所有主机-成功的主机=失败的主机,您可以使用以下任务获取以下两个特殊变量之间的区别:游戏中的所有主机(包括发生故障的主机)和尚未发生故障的所有主机.使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆