# Nested variables inside templates

**URL:** <https://forum.ansible.com/t/nested-variables-inside-templates/27750>\
**Category:** Ansible Project\
**Created:** [June 8, 2018, 3:33pm UTC](https://forum.ansible.com/t/nested-variables-inside-templates/27750 "2018-06-08T15:33:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [June 8, 2018, 3:33pm UTC](https://forum.ansible.com/t/nested-variables-inside-templates/27750/1 "2018-06-08T15:33:54Z")

</div>

Interfaces are different for every server I’m working with, so to print details of each interface, let’s say I’m using the following code in a template:

`interfaces: {% for a_value in ansible_interfaces %}{{ a_value }} {% endfor %}`

Now this ends up printing:

`interfaces: lo enp0s3 enp0s8`

This gives us variables ansible\_`lo`, ansible\_enp0s3, ansible\_enp0s8 that I want to refer.

Is there any way I can print the value of ansible\_`lo.value ``using the loop above?`

`Thanks.`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 8, 2018, 5:16pm UTC](https://forum.ansible.com/t/nested-variables-inside-templates/27750/2 "2018-06-08T17:16:23Z")

</div>

To my knowledge ansible\_\<interface\> doesn't have a key called value, but you can use the content of a key like this

&nbsp;&nbsp;&nbsp;{{ vars['ansible\_' ~ a\_value].\<key\> }}

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [June 9, 2018, 7:34pm UTC](https://forum.ansible.com/t/nested-variables-inside-templates/27750/3 "2018-06-09T19:34:04Z")

</div>

Thanks! That’s exactly what I wanted!

I mistyped ‘active’ as ‘value’. Not sure what was going on in my head haha.
