Nested variable expansion

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

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.

Thanks Matt! This works for me :slight_smile:

Anand