Hi ,
My VM has 4 ip-interfaces . I want to extract a data as below using ansible.
Interface1: macaddress
Interface2: macaddress
Interface3: macaddress
Interface4: macaddress
Kindly help.
Hi ,
My VM has 4 ip-interfaces . I want to extract a data as below using ansible.
Interface1: macaddress
Interface2: macaddress
Interface3: macaddress
Interface4: macaddress
Kindly help.
Assuming you have all macs in a list:
name: process mac addresses into a list
set_fact:
result: “{{result | default() | union([ ‘Interface’ + idx|string + ': ’ + item]) }}”
loop: “{{macs}}”
loop_control:
index_var: idx
name: set fact
set_fact:
final: “{{result|join(‘\n’)}}”
You could use a template like this:
{% for iface in ansible_interfaces | difference(['lo','eth0']) | sort %}
{{ iface }}: {{ hostvars[inventory_hostname]['ansible_' ~
iface]['macaddress'] }}
{% endfor %}
This will yield:
eth1: 08:00:27:b3:59:d0
eth2: 08:00:27:87:1b:de
eth3: 08:00:27:9b:80:85
eth4: 08:00:27:90:ad:eb
Hi Dick,
Thanks very much for your help.
Thats exactly what i wanted.
Regards
Rakesh