Skip to content

Instantly share code, notes, and snippets.

@johnl
Created August 17, 2018 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnl/74b775dc21971ef71e4c0095bdf70162 to your computer and use it in GitHub Desktop.
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.
# 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