如果第一次失败,Ansible使用不同的主机名

问题描述 投票:0回答:2

我换了一些覆盆子的pis(一次只运行一次)并运行ansible。大多数pis回应ping raspberrypi,但我有一个响应ping raspberrypi.local

而不是记得在执行剧本之前手动ping正确的主机名,如果第一个失败,有没有办法在不同的主机名上运行一个剧本?

目前我的剧本是

---
- hosts: raspberrypi

/etc/ansible/hosts

[raspberrypi]
raspberrypi
#raspberrypi.local

如果我取消注释掉第二个主机名并且第一个主机名失败,那么该剧本将失败并且不会在.local主机名上运行

ansible hosts
2个回答
1
投票

我不确定这是否可以直接用于ansible。

但我能想到的一个黑客攻击是创建一个主机列表,将它们存储在变量中,使用localhost执行ping操作。如果ping成功,请创建自定义主机组并执行您要执行的任务。

你也用串口执行你的剧本:1?

希望如此有帮助。


0
投票

您可以针对两个主机组运行游戏。

- hosts: raspberrypi:raspberrypi.local
© www.soinside.com 2019 - 2024. All rights reserved.