# group var inside jinja loop

**URL:** <https://forum.ansible.com/t/group-var-inside-jinja-loop/19680>\
**Category:** Ansible Project\
**Created:** [November 3, 2015, 10:10am UTC](https://forum.ansible.com/t/group-var-inside-jinja-loop/19680 "2015-11-03T10:10:18Z")\
**Posts on this page:** 2\
**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:** [November 3, 2015, 10:10am UTC](https://forum.ansible.com/t/group-var-inside-jinja-loop/19680/1 "2015-11-03T10:10:18Z")

</div>

Hi,

having a jinja loop

{% for host in groups[‘server\_group’] %} --dns={{ hostvars[host][‘ansible\_eth0’][‘ipv4’][‘address’] }} {% endfor %}

i want to change “eth0” with a group\_var as the interface some times differs. I know i could do a “ansible\_eth1” in the template but i had to do this in a lot of places so i thought using group\_var (interface) would be ok.

I tried {% for host in groups[‘server\_group’] %} --dns={{ hostvars[host][‘ansible\_{{interface}}’][‘ipv4’][‘address’] }} {% endfor %}

and a lot of other but always ended with a error. How can i use a group\_var inside of this loop?

Cheers,

Mike

---

<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:** [November 4, 2015, 10:29am UTC](https://forum.ansible.com/t/group-var-inside-jinja-loop/19680/2 "2015-11-04T10:29:54Z")

</div>

solved it with

{% for host in groups[‘server\_group’] %} --dns={{ hostvars[host][nic].ipv4.address }} {% endfor %}

where nic is a group var.
