# Work with Jinja/template issue

**URL:** <https://forum.ansible.com/t/work-with-jinja-template-issue/22405>\
**Category:** Ansible Project\
**Created:** [August 27, 2016, 3:20am UTC](https://forum.ansible.com/t/work-with-jinja-template-issue/22405 "2016-08-27T03:20:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lupindeterd](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lupindeterd](https://forum.ansible.com/u/lupindeterd)\
**Post date:** [August 27, 2016, 3:20am UTC](https://forum.ansible.com/t/work-with-jinja-template-issue/22405/1 "2016-08-27T03:20:55Z")

</div>

Hi,

I want to gather all the NICs and its IP address from facts. So I tried iterating to all interfaces, i.e

{% for nic in ansible\_interfaces %}  
{% set present\_nic = ‘facter\_ipaddress\_%s’ | format( nic ) %}

> {{ nic }} | {{ present\_nic }} |  
> {% endfor %}

The present\_nic variable turn into some form of string and won’t evaluate object anymore. ☹

I wanted to grab the value of 'facter\_ipaddress\_{{ nic }} key, but instead got a literal string.

> _NIC_ | _IP_ | _Netmask_ |  
> lo | facter\_ipaddress\_lo |  
> enp0s3 | facter\_ipaddress\_enp0s3 |  
> enp0s8 | facter\_ipaddress\_enp0s8 |

Is there a way to get around with this, without resorting to writing a custom facts/module?

TIA,  
Lupin

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 31, 2016, 3:00pm UTC](https://forum.ansible.com/t/work-with-jinja-template-issue/22405/2 "2016-08-31T15:00:11Z")

</div>

> Hi,
> 
> I want to gather all the NICs and its IP address from facts. So I tried  
> iterating to all interfaces, i.e
> 
> {% for nic in ansible\_interfaces %}  
> &nbsp;&nbsp;{% set present\_nic = 'facter\_ipaddress\_%s' | format( nic ) %}  
> \> {{ nic }} | {{ present\_nic }} |  
> {% endfor %}
> 
> The present\_nic variable turn into some form of string and won't evaluate  
> object anymore. ☹
> 
> I wanted to grab the value of 'facter\_ipaddress\_{{ nic }} key, but instead  
> got a literal string.
> 
> \> \*NIC\* | \*IP\* | \*Netmask\* |  
> &nbsp;&nbsp;\> lo | facter\_ipaddress\_lo |  
> &nbsp;&nbsp;\> enp0s3 | facter\_ipaddress\_enp0s3 |  
> &nbsp;&nbsp;\> enp0s8 | facter\_ipaddress\_enp0s8 |
> 
> Is there a way to get around with this, without resorting to writing a  
> custom facts/module?

{% for nic in ansible\_interfaces %}

> {{ nic }} | {{ hostvars[inventory\_hostname]['facter\_ipaddress\_' + nic]

}} |  
{% endfor %}
