仅打印失败的任务 - Ansible [英] Print out only failed tasks - Ansible
问题描述
我创建了一个 Ansible playbook,它只检查特定端口上与目标主机的连接.这是我的剧本
I have created an Ansible playbook which just checks the connection to target hosts on a specific port. Here is my playbook
- name: ACL check to target machines.
hosts: all
gather_facts: False
vars:
target_hosts:
- server1 18089
- server1 8089
- server1 18000
tasks:
- name: execute the command
command: "nc -vz {{ item }}"
with_items: "{{ target_hosts }}"
执行剧本时得到的输出包含已更改(成功)和失败.
The output i get when i execute the playbook contains both changed(success) and failed.
在实际场景中,我有很多目标主机,&我的输出非常大.
In real scenario i have many number of target hosts, & my output is very large.
我想要的是,我希望在底部有最终报告,其中仅显示源和目标之间所有失败连接的列表.
What i wanted here is, i want to have final report at bottom which shows only list of all failed connections between source and target.
谢谢
推荐答案
我想在底部有最终报告,只显示源和目标之间所有失败连接的列表
i want to have final report at bottom which shows only list of all failed connections between source and target
我相信您正在寻找的旋钮是 stdout 回调插件.虽然我没有看到一个完全如你所愿,但有两个似乎可以让你接近:
I believe the knob you are looking for is stdout callback plugins. While I don't see one that does exactly as you wish, there are two of them that seem like they may get you close:
actionable 声称它只会发出失败和更改的事件:
The actionable one claims it will only emit Failed and Changed events:
$ ANSIBLE_STDOUT_CALLBACK=actionable ansible-playbook ...
然后,向上移动复杂性阶梯,json 顾名思义,它会以 JSON 格式发出步骤记录,允许您根据自己的需要过滤完全的输出(.failed
是一个布尔值每个任务都表明这一点):
Then, moving up the complexity ladder, the json one will, as its name implies, emit a record of the steps in JSON, allowing you to filter the output for exactly what you want (.failed
is a boolean on each task that indicates just that):
$ ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ...
然后,正如插件"部分所暗示的那样,如果您愿意,您也可以实现自己的正是您想要的;提供了大量示例,除了文档.
Then, as the "plugins" part implies, if you were so inclined you could also implement your own that does exactly what you want; there are a lot of examples provided, in addition to the docs.
这篇关于仅打印失败的任务 - Ansible的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!