# Facts of other hosts in the case of unreachability

**URL:** <https://forum.ansible.com/t/facts-of-other-hosts-in-the-case-of-unreachability/12986>\
**Category:** Ansible Project\
**Created:** [June 19, 2013, 10:07am UTC](https://forum.ansible.com/t/facts-of-other-hosts-in-the-case-of-unreachability/12986 "2013-06-19T10:07:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 19, 2013, 10:07am UTC](https://forum.ansible.com/t/facts-of-other-hosts-in-the-case-of-unreachability/12986/1 "2013-06-19T10:07:18Z")

</div>

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.

&nbsp;&nbsp;clients =   
&nbsp;&nbsp;for host, vars in hostvars.iteritems():  
&nbsp;&nbsp;&nbsp;&nbsp;if vars.get('icinga\_server\_ip') == ansible\_default\_ipv4:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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,

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 19, 2013, 3:16pm UTC](https://forum.ansible.com/t/facts-of-other-hosts-in-the-case-of-unreachability/12986/2 "2013-06-19T15:16:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 19, 2013, 4:27pm UTC](https://forum.ansible.com/t/facts-of-other-hosts-in-the-case-of-unreachability/12986/3 "2013-06-19T16:27:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [June 19, 2013, 9:40pm UTC](https://forum.ansible.com/t/facts-of-other-hosts-in-the-case-of-unreachability/12986/4 "2013-06-19T21:40:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 19, 2013, 11:55pm UTC](https://forum.ansible.com/t/facts-of-other-hosts-in-the-case-of-unreachability/12986/5 "2013-06-19T23:55:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 20, 2013, 5:50am UTC](https://forum.ansible.com/t/facts-of-other-hosts-in-the-case-of-unreachability/12986/6 "2013-06-20T05:50:07Z")

</div>

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 😉
