Last active
December 14, 2015 03:09
-
-
Save vjanelle/5019346 to your computer and use it in GitHub Desktop.
Generates facts to identify the interface a mac address is associated with
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fact: | |
# macaddresses to interfaces | |
# | |
# Purpose: | |
# Make a fact to detail the interfaces for a normalized mac address | |
# | |
# Caveats: | |
# Only tested on linux, deals with 802.3ad bonded links, but I have not | |
# tested other kinds of interfaces | |
# | |
require 'facter/util/macaddress' | |
# Delete lo interface, as it doesn't have a mac | |
Facter::Util::IP.get_interfaces.delete_if {|interface| interface == 'lo' || interface =~ /sit\d+/ }.each do |interface| | |
# if we don't have a hardware address, skip | |
hwaddr = Facter::Util::IP.get_interface_value(interface, 'macaddress') | |
if hwaddr == nil | |
next | |
end | |
# If the device has a master, skip it | |
if Facter::Util::IP.get_bonding_master(interface) == nil | |
# mac_AA_BB_CC... => eth0 | |
label = "mac_" + hwaddr.gsub(/:/,'_').downcase | |
Facter.add(label) do | |
setcode do | |
interface | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment