RikSaunderson
RikSaunderson

Reputation: 3755

Puppet: Get MAC address for specified ethernet interface

I'm trying to populate a config file with a MAC address for a specified ethernet adapter.

The name of the ethernet adapter (e.g. eth1) is a parameter of my defined type. When I try to populate a config file through puppet with an erb template which accesses the macaddress facter fact, that gives me the mac address for the eth0 interface, which is the wrong one (in this instance).

How can I create a variable in my defined type which takes the value of facter macaddress_ethernetinterface where ethernetinterface is defined by a parameter of the defined type?

Upvotes: 1

Views: 1506

Answers (1)

Felix Frank
Felix Frank

Reputation: 8223

There is a whole family of macaddress facts, one for each interface.

notify { "eth1 has ${macaddress_eth1}": }

In your template, you can access the variable name that includes a parameter (say, $interface) like

<%= scope.lookupvar("macaddress_#{ @interface }") %>

Future versions of Facter will supply a hash that will allow looking up MAC addresses per interface.

Upvotes: 1

Related Questions