-
-
Save TraGicCode/043dd3838ebba3026610376593f92e3a to your computer and use it in GitHub Desktop.
Datacenter Fact
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
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