# Nested variable expansion

**URL:** <https://forum.ansible.com/t/nested-variable-expansion/14145>\
**Category:** Ansible Project\
**Created:** [December 12, 2013, 11:01pm UTC](https://forum.ansible.com/t/nested-variable-expansion/14145 "2013-12-12T23:01:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [December 12, 2013, 11:01pm UTC](https://forum.ansible.com/t/nested-variable-expansion/14145/1 "2013-12-12T23:01:54Z")

</div>

Hello ansible devs and users,

In a variables file, I’d like to do something like this:

iface: eth0  
address:“{{ ansible\_{{ iface }}.ipv4.address }}”

However, this does not work. In a task or template, instead of getting the IPv4 address of eth0, the “address” variable ends up being just “{{ ansible\_{{ iface }}.ipv4.address }}”.

Is there any way to achieve what I want to do?

Regards,

Anand

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 12, 2013, 11:25pm UTC](https://forum.ansible.com/t/nested-variable-expansion/14145/2 "2013-12-12T23:25:15Z")

</div>

I believe this should be:

“{{ hostvars[inventory\_hostname][‘ansible\_’ + iface].ipv4.address }}”

There are other variations too, but this should get you what you want.

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [December 13, 2013, 12:02am UTC](https://forum.ansible.com/t/nested-variable-expansion/14145/3 "2013-12-13T00:02:39Z")

</div>

Thanks Matt! This works for me 🙂

Anand
