Work with Jinja/template issue

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. :frowning:

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

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. :frowning:

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?

{% for nic in ansible_interfaces %}

{{ nic }} | {{ hostvars[inventory_hostname]['facter_ipaddress_' + nic]

}} |
{% endfor %}