Skip to content

Instantly share code, notes, and snippets.

@TraGicCode
Forked from natemccurdy/datacenter.rb
Created February 6, 2018 19:22
Show Gist options
  • Save TraGicCode/043dd3838ebba3026610376593f92e3a to your computer and use it in GitHub Desktop.
Save TraGicCode/043dd3838ebba3026610376593f92e3a to your computer and use it in GitHub Desktop.
Datacenter Fact
require 'ipaddr'
# Accessible in puppet as $::datacenter
Facter.add(:datacenter) do
setcode do
# Mapping of vlans to ipaddresses
# NOTE: To extend this fact, modify this hash
vlan_segments = {
'prod' => IPAddr.new('10.10.10.0/22'),
'dev' => IPAddr.new('11.11.11.0/22'),
'uat' => IPAddr.new('12.12.12.0/22'),
'cloud' => [
IPAddr.new('13.13.13.0/24'),
IPAddr.new('15.15.15.0/24')
]
}
segment_name = nil
# Iterate through all segments and find the one that matches
vlan_segments.each do |segment, subnets|
Array(subnets).each do |address|
segment_name = segment if address.include?(Facter.value(:ipaddress))
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment