# AnsibleUndefinedVariable

**URL:** <https://forum.ansible.com/t/ansibleundefinedvariable/17941>\
**Category:** Ansible Project\
**Created:** [April 9, 2015, 11:43am UTC](https://forum.ansible.com/t/ansibleundefinedvariable/17941 "2015-04-09T11:43:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Michel](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Mike\_Michel](https://forum.ansible.com/u/Mike_Michel)\
**Post date:** [April 9, 2015, 11:43am UTC](https://forum.ansible.com/t/ansibleundefinedvariable/17941/1 "2015-04-09T11:43:34Z")

</div>

hi,

im running a master/slave cluster where i want to add another slave via ansible so i am limiting the play to the new slave

ansible-playbook -vvv -l mesos\_slaves[3] -i hosts-prod.yml playbook.yml -u xxx -k -K

Add a point there comes a template which needs the ips of the other slaves

`

{% for host in groups[‘mesos\_slaves’] %}  
{{ hostvars[host][‘ansible\_eth0’][‘ipv4’][‘address’] }}"  
{% endfor %}

`

where mesos\_slaves is

`

[mesos\_slaves]  
slave01  
slave02  
slave03  
slave04

`

The play ends there with

`

fatal: [slave04] =\> {‘msg’: “AnsibleUndefinedVariable: One or more undefined variables: ‘dict object’ has no attribute ‘ansible\_eth0’”, ‘failed’: True}  
fatal: [slave04] =\> {‘msg’: “AnsibleUndefinedVariable: One or more undefined variables: ‘dict object’ has no attribute ‘ansible\_eth0’”, ‘failed’: True}

`

but a

`  
ansible -i hosts-prod.yml slave01 -m setup -a “filter=_eth0_”

`

gives me

`

slave01 | success \>\> {  
“ansible\_facts”: {  
“ansible\_eth0”: {  
“active”: true,  
“device”: “eth0”,  
“ipv4”: {  
“address”: “192.168.0.12”,

`

Why is it not working in the play?

Mike

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 9, 2015, 4:21pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable/17941/2 "2015-04-09T16:21:52Z")

</div>

I'm guessing you are not gathering facts for the others

---

<div class="post-metadata">

**Author:** ![Mike\_Michel](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Mike\_Michel](https://forum.ansible.com/u/Mike_Michel)\
**Post date:** [April 9, 2015, 5:02pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable/17941/3 "2015-04-09T17:02:19Z")

</div>

how can i do it while limiting to one host?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 9, 2015, 7:42pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable/17941/4 "2015-04-09T19:42:54Z")

</div>

A couple of ways, the simplest would be 2 plays, the first just  
gathers facts on all hosts, the 2nd is limited to a single host, facts  
are kept in memory cache by default. Another way is just setting up  
persistent fact caching.
