Created
August 17, 2018 15:32
-
-
Save johnl/74b775dc21971ef71e4c0095bdf70162 to your computer and use it in GitHub Desktop.
Puppet Facter v2+v3 compatible broadcast address fact provider. Get broadcast address for each available network interface.
This file contains hidden or 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: broadcast | |
# | |
# Purpose: | |
# Get broadcast addresses for each interface. | |
# | |
Facter.value('interfaces').split(',').each do |interface| | |
Facter.add("broadcast_" + interface) do | |
setcode do | |
require 'ipaddr' | |
netmask = Facter.value('netmask_'+interface) | |
ip = Facter.value('ipaddress_'+interface) | |
if netmask and ip | |
ip = IPAddr.new(ip, Socket::AF_INET) | |
subnet = IPAddr.new(netmask, Socket::AF_INET) | |
ip.mask(subnet.to_s).to_range.last.to_s | |
else | |
nil | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment