# Ansible : Accessing a variable containing a :

**URL:** <https://forum.ansible.com/t/ansible-accessing-a-variable-containing-a/13710>\
**Category:** Ansible Project\
**Created:** [October 17, 2013, 9:37pm UTC](https://forum.ansible.com/t/ansible-accessing-a-variable-containing-a/13710 "2013-10-17T21:37:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Old\_Karkass](https://avatars.discourse-cdn.com/v4/letter/o/a6a055/32.png) [@Old\_Karkass](https://forum.ansible.com/u/Old_Karkass)\
**Post date:** [October 17, 2013, 9:37pm UTC](https://forum.ansible.com/t/ansible-accessing-a-variable-containing-a/13710/1 "2013-10-17T21:37:25Z")

</div>

Hi

I’ve got an issue with the variables coming from the setup module  
It list all the network interfaces on the target system and I need to reuse the ip address from the eth0:0 interface in a template

From the setup module :

“ansible\_eth0”: {  
“active”: true,  
“device”: “eth0”,  
“ipv4”: {  
“address”: “10.0.2.15”,  
“netmask”: “255.255.255.0”,  
“network”: “10.0.2.0”  
},  
“ipv6”: [  
{  
“address”: “fe80::a00:27ff:febb:8ca9”,  
“prefix”: “64”,  
“scope”: “link”  
}  
],  
“macaddress”: “08:00:27:bb:8c:a9”,  
“module”: “e1000”,  
“mtu”: 1500,  
“type”: “ether”  
},  
**“ansible\_eth0:0”** : {  
“active”: true,  
“device”: “eth0”,  
“ipv4”: {  
“address”: “192.168.77.60”,  
“netmask”: “255.255.255.0”,  
“network”: “192.168.77.0”  
},  
“macaddress”: “08:00:27:bb:8c:a9”,  
“module”: “e1000”,  
“mtu”: 1500,  
“type”: “ether”  
},

To access it i’ve tried different format but either the play stopped or in the final file, the name of the variable is written not the content  
{{ “ansible\_eth0:0.ipv4.address” }}  
{{ “ansible\_eth0:0”.ipv4.address }}

And same with the $ notation

Is there a way to get it or is it a bug ?

Thanks  
Frank

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 18, 2013, 4:28pm UTC](https://forum.ansible.com/t/ansible-accessing-a-variable-containing-a/13710/2 "2013-10-18T16:28:03Z")

</div>

“{{ “ansible\_eth0:0.ipv4.address” }}”

Don’t quote things, you’re requesting the template engine return the string you passed in!

{{ hostvars[inventory\_hostname][‘ansible\_eth0:0’][‘ipv4’][‘address’] }}

will work for you

I agree we should replace the “:”'s with an underscore though.

Please file a ticket on github and we will make it so.

---

<div class="post-metadata">

**Author:** ![Old\_Karkass](https://avatars.discourse-cdn.com/v4/letter/o/a6a055/32.png) [@Old\_Karkass](https://forum.ansible.com/u/Old_Karkass)\
**Post date:** [October 21, 2013, 10:32am UTC](https://forum.ansible.com/t/ansible-accessing-a-variable-containing-a/13710/3 "2013-10-21T10:32:01Z")

</div>

Hi Michael

Thanks for the workaround

I’ve tried this in my test environment and confirm it is working fine

Many thanks  
Frank
