# Loading vars about a host which isn't part of the play

**URL:** <https://forum.ansible.com/t/loading-vars-about-a-host-which-isnt-part-of-the-play/14575>\
**Category:** Ansible Project\
**Created:** [February 17, 2014, 2:35am UTC](https://forum.ansible.com/t/loading-vars-about-a-host-which-isnt-part-of-the-play/14575 "2014-02-17T02:35:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_O\_Connel](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@Christopher\_O\_Connel](https://forum.ansible.com/u/Christopher_O_Connel)\
**Post date:** [February 17, 2014, 2:35am UTC](https://forum.ansible.com/t/loading-vars-about-a-host-which-isnt-part-of-the-play/14575/1 "2014-02-17T02:35:13Z")

</div>

Hello,

I’ve been digging through the ansible source, and I believe my current approach to a problem is impossible without making changes in core, which I prefer not to do, so I’m looking for an alternative solution.

In my inventory, I define hosts based on datacenter:

[mia1]  
host1  
host2

[lax2]  
host3  
host4

[ams1]  
host5  
host6

[mia1:vars]  
datacenter\_name=Nap of the Americas  
datacenter\_location=Miami, Florida, USA  
datacenter\_key=mia1

[lax2:vars]  
datacenter\_name=One Wilshire  
datacenter\_location=Los Angeles, California, USA  
datacenter\_key=lax2

[ams1:vars]  
datacenter\_name=Nap of Amsterdam  
datacenter\_location=Amsterdam, Netherlands  
datacenter\_key=ams1

In a vars, I have a vars file defined which sets up a list of hosts:

cluster\_name:

- host1
- host2
- host4
- host5

Given these values, I need to create to template an entry like:

Included Datacenters in {{ cluster\_name }}:

- Nap of the Americas
- One Wilshire
- Nap of Amsterdam

Here’s the problem: I need this to work even when I have the play limited to a single host (which may or may not be one of the hosts in “cluster\_name”. I’ve spent hours digging into this problem, and nothing of tried works. The problem is how to generate a list of “datacenter\_names” knowing only the “cluster\_name”.

Unfortunately, hostvars only contains information about the hosts that are _currently_ part of the run. I understand the difficulties in accessing discovered facts about a node that’s not part of the play. But it seems like accessing defined facts about a node that’s not part of the play should be easy? I could naturally create a giant defined variable like “hostname\_to\_datacenter\_map” and keep a mapping between hostnames and datacenters up to date. I’d really like to avoid this approach, however, because it won’t scale well, especially with dynamically generated inventory files.

Any other solutions that allow me to keep these facts about hosts associated with the inventory would be greatly appreciated.

All the best,

~ Christopher

---

<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:** [February 17, 2014, 3:14pm UTC](https://forum.ansible.com/t/loading-vars-about-a-host-which-isnt-part-of-the-play/14575/2 "2014-02-17T15:14:08Z")

</div>

Don’t use “–limit” in those cases.

Instead use a host specifier.

hosts: “foo{{ additional\_restrictions | default(‘’) }}”

ansible-playbook foo.yml -e “additional\_restrictions=”:&limitToThisGroup"

–Michael
