# hostvars\[inventory\_hostname\]\[ansible\_facts\] when host unreachable?

**URL:** <https://forum.ansible.com/t/hostvars-inventory-hostname-ansible-facts-when-host-unreachable/33667>\
**Category:** Ansible Project\
**Created:** [August 24, 2020, 1:23pm UTC](https://forum.ansible.com/t/hostvars-inventory-hostname-ansible-facts-when-host-unreachable/33667 "2020-08-24T13:23:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trammael](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@Trammael](https://forum.ansible.com/u/Trammael)\
**Post date:** [August 24, 2020, 1:23pm UTC](https://forum.ansible.com/t/hostvars-inventory-hostname-ansible-facts-when-host-unreachable/33667/1 "2020-08-24T13:23:49Z")

</div>

I’ve been trying to loop on a fact for all hosts (‘distribution’) and encountered an error to the effect of ‘dict is undefined’ . It took a while to realize that ‘ansible\_facts:’ exists but is unpopulated on unreachable hosts.

What would be the best way to loop through only reachable hosts that have successfully populated ansible\_facts?

Thank you,

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [August 25, 2020, 11:05am UTC](https://forum.ansible.com/t/hostvars-inventory-hostname-ansible-facts-when-host-unreachable/33667/2 "2020-08-25T11:05:17Z")

</div>

> I've been trying to loop on a fact for all hosts ('distribution') and encountered an error to the effect of 'dict is  
> undefined' . It took a while to realize that 'ansible\_facts:' exists but is unpopulated on unreachable hosts.
> 
> What would be the best way to loop through only reachable hosts that have successfully populated ansible\_facts?
> 
> Thank you,

You could check whether the host is listed in the ansible\_play\_hosts variable which only contains "active"  
hosts.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
