# How can I debug this playbook so that I can properly loop over the hostvars?

**URL:** <https://forum.ansible.com/t/how-can-i-debug-this-playbook-so-that-i-can-properly-loop-over-the-hostvars/16064>\
**Category:** Ansible Project\
**Created:** [August 28, 2014, 5:19pm UTC](https://forum.ansible.com/t/how-can-i-debug-this-playbook-so-that-i-can-properly-loop-over-the-hostvars/16064 "2014-08-28T17:19:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abe\_Voelker](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Abe\_Voelker](https://forum.ansible.com/u/Abe_Voelker)\
**Post date:** [August 28, 2014, 5:19pm UTC](https://forum.ansible.com/t/how-can-i-debug-this-playbook-so-that-i-can-properly-loop-over-the-hostvars/16064/1 "2014-08-28T17:19:24Z")

</div>

I have an inventory file like this:

`  
[redisservers]  
72.14.178.81

[webservers]  
198.58.107.247  
`

I’m trying to run this playbook against the redisservers group to allow access to port 6379 for the webservers:

`

---

<div class="post-metadata">

**Author:** ![Abe\_Voelker](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Abe\_Voelker](https://forum.ansible.com/u/Abe_Voelker)\
**Post date:** [August 28, 2014, 7:25pm UTC](https://forum.ansible.com/t/how-can-i-debug-this-playbook-so-that-i-can-properly-loop-over-the-hostvars/16064/2 "2014-08-28T19:25:04Z")

</div>

So I wrote a template task that populates this jinja template:

`{{ hostvars['198.58.107.247'] }}`

And this is the output I got:

`{'ansible_ssh_user': 'root', 'inventory_hostname_short': '198', 'group_names': ['webservers'], 'inventory_hostname': '198.58.107.247'}`

So hostvars[‘198.58.107.247’] doesn’t seem to be filled with all the facts for that host. Then I realized that the root playbook I’m running (provision.yml) looks like this:

`

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 28, 2014, 9:07pm UTC](https://forum.ansible.com/t/how-can-i-debug-this-playbook-so-that-i-can-properly-loop-over-the-hostvars/16064/3 "2014-08-28T21:07:47Z")

</div>

In Ansible to use facts about a host you must have either:

already gathered facts from that host in that play (just gathering facts would be enough, no tasks needed)

- hosts: webservers:dbservers  
tasks: 

- hosts: webservers # that need to know facts about dbservers  
tasks:

- …

OR

enabled fact caching and previously talked to that host within the cache timeout

[http://docs.ansible.com/playbooks\_variables.html#fact-caching](http://docs.ansible.com/playbooks_variables.html#fact-caching)
