# Another variable within a variable for jinja templates

**URL:** <https://forum.ansible.com/t/another-variable-within-a-variable-for-jinja-templates/21735>\
**Category:** Ansible Project\
**Created:** [June 10, 2016, 4:31pm UTC](https://forum.ansible.com/t/another-variable-within-a-variable-for-jinja-templates/21735 "2016-06-10T16:31:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keith\_Poirier](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@Keith\_Poirier](https://forum.ansible.com/u/Keith_Poirier)\
**Post date:** [June 10, 2016, 4:31pm UTC](https://forum.ansible.com/t/another-variable-within-a-variable-for-jinja-templates/21735/1 "2016-06-10T16:31:37Z")

</div>

What I’m trying to do is get a list of active NICs on a system and build a template using what I find. The playbook looks like:

---

<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:** [June 10, 2016, 6:37pm UTC](https://forum.ansible.com/t/another-variable-within-a-variable-for-jinja-templates/21735/2 "2016-06-10T18:37:06Z")

</div>

You will need to use something like:

{{ hostvars[inventory\_hostname][“ansible\_” ~ dev].ipv4.address }}

---

<div class="post-metadata">

**Author:** ![Keith\_Poirier](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@Keith\_Poirier](https://forum.ansible.com/u/Keith_Poirier)\
**Post date:** [June 15, 2016, 1:19pm UTC](https://forum.ansible.com/t/another-variable-within-a-variable-for-jinja-templates/21735/3 "2016-06-15T13:19:42Z")

</div>

With help from the google + ansible community here is what I have in my template that works:

{% set all\_interfaces = (ansible\_interfaces | difference([‘lo’])) %}  
{% for dev in all\_interfaces %}  
{% set dev\_info = hostvars[inventory\_hostname][‘ansible\_’ + dev] %}  
{% if dev\_info.active %}  
NETWORK\_INTERFACE {{ dev }}  
HEARTBEAT\_IP {{ dev\_info.ipv4.address }}  
{% endif %}  
{% endfor%}
