Another variable within a variable for jinja templates

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:

You will need to use something like:

{{ hostvars[inventory_hostname][“ansible_” ~ dev].ipv4.address }}

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%}