How to obtain the actual hardware macaddress of a network interface via setup module?

1,182 views
Skip to first unread message

Don Jackson

unread,
Jan 30, 2017, 6:48:30 PM1/30/17
to Ansible Project

I am transitioning my network interface provisioning to be based on actual hardware/NIC macaddresses rather than trying to use device names like ethN that seem to be inconsistent between different servers and are often different on each OS distribution

I ran into an issue where Ansible reported the macaddress of a bond member as the macadress of the bond itself, which is not what I need/want.

I am able to work around the issue by installing Facter and using something like:

hostvars[inventory_hostname]['facter_networking']['interfaces'][item].mac

which seems to always report the actual NIC macaddress....

But this means I need to install Facter before I configure my network, which is not ideal.

Is there a way to get this info/fact from Ansible without relying on Facter?

Even if I have to install my own facts.....






Klaus Ethgen

unread,
Jan 31, 2017, 7:35:25 AM1/31/17
to ansible...@googlegroups.com
Don Jackson <d...@drivescale.com> schrieb:
> I am transitioning my network interface provisioning to be based on actual
> hardware/NIC macaddresses rather than trying to use device names like ethN
> that seem to be inconsistent between different servers and are often
> different on each OS distribution
>
> I ran into an issue where Ansible reported the macaddress of a bond member
> as the macadress of the bond itself, which is not what I need/want.
>
> I am able to work around the issue by installing Facter and using something
> like:
>
> hostvars[inventory_hostname]['facter_networking']['interfaces'][item].mac

{{ ansible_eth0.macaddress }}

If you need to iterate over the interfaces, you have to use:

{{ hostvars[inventory_hostname]['ansible_' + item]['macaddress'] }}

See also [0].

[Removing all unreadable HTML crap]

Regards
Klaus

[0] https://docs.ansible.com/ansible/faq.html#how-do-i-access-a-variable-name-programmatically
--
Klaus Ethgen http://www.ethgen.ch/
pub 4096R/4E20AF1C 2011-05-16 Klaus Ethgen <Kl...@Ethgen.ch>
Fingerprint: 85D4 CA42 952C 949B 1753 62B3 79D0 B06F 4E20 AF1C

Don Jackson

unread,
Jan 31, 2017, 6:06:51 PM1/31/17
to Ansible Project
The problem is that {{ ansible_eth0.macaddress }} doesn't always report the hardware macaddress.

I described this specific issue in my initial post.

For example, if eth0 is part of bond/link-aggregation-group, Ansible returns the macaddress of the bond/LAG, NOT the macaddress of the eth0 interface itself.

Facter apparently obtains the macaddress another way, which in my experience returns the actual macaddress, not the macaddress of the bond....

So that is my question.

How can I get Ansible itself to return the actual macaddress, or do I always have to just use Facter?
Reply all
Reply to author
Forward
0 new messages