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…
Don Jackson <dcj@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
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?