Dear list,
Ansible usually gathers facts from all targetted hosts before any
other tasks are run. Those facts are then available subsequently to
all hosts.
One logical use case of this could be to automatically populate the
list of hosts to monitor with Icinga (Nagios). The following code
would run on the Icinga server and populate a list of hostnames that
have their fact $icinga_server_ip set to the same IP as the Icinga
server.
clients =
for host, vars in hostvars.iteritems():
if vars.get('icinga_server_ip') == ansible_default_ipv4:
clients.append(host)
This all looks nice, but what happens when a host is unreachable?
In that case, the hostvars dictionary will *not* contain an entry
for this host. As a result, the host will be taken out of the Icinga
configuration when Ansible runs. If worst comes to worst, then
Icinga will never be able to alert the administrator that a host
went down, because Ansible made it forget about the host before it
checked it.
Have you any ideas how to mitigate this?
Is there a way to cache hostvars (or subsets of it), such that if
a host was unreachable, the data from the last successful poll would
get used?
Thanks,