# ansible-playbook: How to gather facts from machine Y although you run with --limit="X"

**URL:** <https://forum.ansible.com/t/ansible-playbook-how-to-gather-facts-from-machine-y-although-you-run-with-limit-x/17233>\
**Category:** Ansible Project\
**Created:** [January 10, 2015, 3:06pm UTC](https://forum.ansible.com/t/ansible-playbook-how-to-gather-facts-from-machine-y-although-you-run-with-limit-x/17233 "2015-01-10T15:06:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Feliksik1](https://avatars.discourse-cdn.com/v4/letter/e/c67d28/32.png) [@Eric\_Feliksik1](https://forum.ansible.com/u/Eric_Feliksik1)\
**Post date:** [January 10, 2015, 3:06pm UTC](https://forum.ansible.com/t/ansible-playbook-how-to-gather-facts-from-machine-y-although-you-run-with-limit-x/17233/1 "2015-01-10T15:06:57Z")

</div>

I have an ansible role for machine X that uses use {{ hostvars[‘Y’][‘network\_address’] }} in a task.

If I run ‘ansible-playbook -i inventories/dev site.yml --limit=“X”’ (Vagrant also runs it with --limit) this variable is not available. How can I explicitly declare the dependency on the host Y in the ansible playbook, such that ansible gathers facts (in this case, the ./host\_vars/Y file) for host Y?

Thanks in advance,  
Eric

---

<div class="post-metadata">

**Author:** ![Ulrich\_Hochholdinger](https://avatars.discourse-cdn.com/v4/letter/u/839c29/32.png) [@Ulrich\_Hochholdinger](https://forum.ansible.com/u/Ulrich_Hochholdinger)\
**Post date:** [January 10, 2015, 11:47pm UTC](https://forum.ansible.com/t/ansible-playbook-how-to-gather-facts-from-machine-y-although-you-run-with-limit-x/17233/2 "2015-01-10T23:47:57Z")

</div>

Hi Eric,  
You can describe the inventory on the commandline (look on the trailing comma in the inventory-option ;-D):

ansible-playbook -i"X,Y," site.yml

then inside your playbook have one “hosts: all” only for fact gathering and another for “hosts: X” for the tasks to run on host X.

Cheers  
Ulli

---

<div class="post-metadata">

**Author:** ![Tom\_Bamford](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@Tom\_Bamford](https://forum.ansible.com/u/Tom_Bamford)\
**Post date:** [January 12, 2015, 5:24am UTC](https://forum.ansible.com/t/ansible-playbook-how-to-gather-facts-from-machine-y-although-you-run-with-limit-x/17233/3 "2015-01-12T05:24:08Z")

</div>

Hi Eric

There is a feature called Fact Caching which can facilitate this: [http://docs.ansible.com/playbooks\_variables.html#fact-caching](http://docs.ansible.com/playbooks_variables.html#fact-caching)

Regards  
Tom
