# Is it possible to get facts from host which are not in the current play?

**URL:** <https://forum.ansible.com/t/is-it-possible-to-get-facts-from-host-which-are-not-in-the-current-play/14641>\
**Category:** Ansible Project\
**Created:** [February 24, 2014, 3:27pm UTC](https://forum.ansible.com/t/is-it-possible-to-get-facts-from-host-which-are-not-in-the-current-play/14641 "2014-02-24T15:27:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vidar\_Langseid](https://avatars.discourse-cdn.com/v4/letter/v/6de8d8/32.png) [@Vidar\_Langseid](https://forum.ansible.com/u/Vidar_Langseid)\
**Post date:** [February 24, 2014, 3:27pm UTC](https://forum.ansible.com/t/is-it-possible-to-get-facts-from-host-which-are-not-in-the-current-play/14641/1 "2014-02-24T15:27:11Z")

</div>

Hi

I have a inventory ( hosts ):  
[webservers]  
web-1  
web-2

[nfsserver]  
nfs-1

I then have a nfs role ( nfs.yml) :

- hosts: nfsserver  
user: root  
any\_errors\_fatal: yes  
roles:
- role: common
- role: nfsserver

For various reasons ( like getting IP of all the webservers in order to set FW rules ) I need to access facts for web-1 and web-2, but not execute any tasks on these webservers.  
Is that possible to force loading of facts for groups which are not in the current play?

The only way I can figure how to do that is a bit lame:

- let nfs.yml also include webservers in hosts: statement ( “hosts: webservers:nfsserver” )
- set some variable for nfs-1 ( like “nfsserver=true” in inventory file)
- in every action in roles/nfsserver/tasks/main.yml include a “when: nfsserver is defined and nfsserver == ‘true’”

If not using roles at all, this is not a problem as you can include multiple playbooks, where each playbook has it’s “hosts:” definition. In order to load facts for all hosts, you therefore may just include one playbook with “hosts: webservers:nfsservers”, but with no actions ( or a dummy one… )

Best regards,  
Vidar

---

<div class="post-metadata">

**Author:** ![Nick\_Groenen](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@Nick\_Groenen](https://forum.ansible.com/u/Nick_Groenen)\
**Post date:** [February 24, 2014, 3:34pm UTC](https://forum.ansible.com/t/is-it-possible-to-get-facts-from-host-which-are-not-in-the-current-play/14641/2 "2014-02-24T15:34:53Z")

</div>

You can hit all hosts in a separate play in the playbook, then apply  
your roles only to a select group of hosts in a later play. The facts  
will be available throughout the entire playbook run and not be  
limited to only the hosts you specified in the second play. So instead  
of your example above, you would get:

- hosts: all  
&nbsp;&nbsp;gather\_facts: yes

- hosts: nfsserver  
&nbsp;&nbsp;user: root  
&nbsp;&nbsp;any\_errors\_fatal: yes  
&nbsp;&nbsp;roles:  
&nbsp;&nbsp;&nbsp;&nbsp;- role: common  
&nbsp;&nbsp;&nbsp;&nbsp;- role: nfsserver

---

<div class="post-metadata">

**Author:** ![Vidar\_Langseid](https://avatars.discourse-cdn.com/v4/letter/v/6de8d8/32.png) [@Vidar\_Langseid](https://forum.ansible.com/u/Vidar_Langseid)\
**Post date:** [February 24, 2014, 4:10pm UTC](https://forum.ansible.com/t/is-it-possible-to-get-facts-from-host-which-are-not-in-the-current-play/14641/3 "2014-02-24T16:10:05Z")

</div>

Ahh....  
I was not aware of the fact that you could define 2 plays in the same  
file like that....  
It works like a charm.. Thanx!

Best regards,  
Vidar
