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

89 views
Skip to first unread message

Eric Feliksik

unread,
Jan 10, 2015, 10:06:57 AM1/10/15
to ansible...@googlegroups.com
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

Ulrich Hochholdinger

unread,
Jan 10, 2015, 6:47:57 PM1/10/15
to ansible...@googlegroups.com
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

Tom Bamford

unread,
Jan 12, 2015, 12:24:31 AM1/12/15
to ansible...@googlegroups.com
Hi Eric

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

Regards
Tom


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6dba276f-6585-44dd-a66c-c20b41ef7ab9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



Reply all
Reply to author
Forward
0 new messages