我们使用ansible来配置一些主机,包括IP配置。我们不想使用 DHCP 服务器。有时我们会向网络添加新主机。这些新主机在一个 IP 地址范围内,而现有的生产主机在另一个 IP 地址范围内。我们只是将新主机放在第一个网络中,然后让 ansible 配置它们,测试它们并将 IP 更改为生产范围。Ansible 通过 cron 定期运行。
但是,当没有新主机时,ansible 会报 unreachable 错误。没有新的主机是通常的情况。我怎样才能抑制它或让它不那么突出?
基本上我们的剧本是这样的:
---
# configure existing hosts
- hosts: production
tasks:
- name: do regular maintenance
# ...
- hosts: new
# Does not seem to do anything
ignore_errors: True
tasks:
- name: configure freshly discovered host
# ...
- name: test freshly discovered host
# ...
- name: change ip config to production network
# ...
Run Code Online (Sandbox Code Playgroud)
/etc/ansible/hosts 看起来像这样:
[production]
192.168.2.[11:255]
[new]
# …Run Code Online (Sandbox Code Playgroud) ansible ×1