group var inside jinja loop

33 views
Skip to first unread message

Mike Michel

unread,
Nov 3, 2015, 5:10:18 AM11/3/15
to Ansible Project
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

Mike Michel

unread,
Nov 4, 2015, 5:29:54 AM11/4/15
to Ansible Project
solved it with 

{% for host in groups['server_group'] %} --dns={{ hostvars[host][nic].ipv4.address }} {% endfor %} 


where nic is a group var.
Reply all
Reply to author
Forward
0 new messages