Facts of other hosts in the case of unreachability

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,

Instead of using hostvars, use groups[“foo”] which is the list of all hostnames in group foo.

also sprach Michael DeHaan <michael@ansibleworks.com> [2013.06.19.1716 +0200]:

Instead of using hostvars, use groups["foo"] which is the list of
all hostnames in group foo.

But this won't solve the problem, right? I mean, groups["foo"]
includes the hostname even if the host is down, alright, but I won't
be able to query that host's facts during a run when the host is
down, or will I?

but you can see that you have the host and no facts, which you can use to skip ‘removing’.

You can’t have facts about down hosts in the present implementation.

I am considering making the facts cache pesistent, however. Possibly in this release or the next.

also sprach Michael DeHaan <michael@ansibleworks.com> [2013.06.20.0155 +0200]:

You can't have facts about down hosts in the present
implementation.

I am considering making the facts cache pesistent, however.
Possibly in this release or the next.

Oh, awesome! Count me as an early tester :wink: