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

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

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

Hi Eric

There is a feature called Fact Caching which can facilitate this: http://docs.ansible.com/playbooks_variables.html#fact-caching

Regards
Tom