Work with Jinja/template issue

15 views
Skip to first unread message

Lupin Deterd

unread,
Aug 26, 2016, 11:21:07 PM8/26/16
to ansible...@googlegroups.com
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

Kai Stian Olstad

unread,
Aug 31, 2016, 11:00:58 AM8/31/16
to ansible...@googlegroups.com
| {{ nic }} | {{ hostvars[inventory_hostname]['facter_ipaddress_' + nic]
}} |
{% endfor %}

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages