puppet-prod/modules/facts/lib/facter/country.rb
Ben Vincent 1f7b347ef4 refacter: tidy facts
- create a facts module, move all facts to this module
2024-02-17 22:57:36 +11:00

29 lines
633 B
Ruby

# frozen_string_literal: true
# set country based on the subnet
Facter.add('country') do
setcode do
# use facts['networking']['ip']to find the promary IP address
ip = Facter.value(:networking)['ip']
# subnet to region mapping
subnet_to_country = {
'198.18.17.0/24' => 'au'
}
require 'ipaddr'
# Find the region for the IP
country = 'stateless' # default to 'stateless' if no country matches
subnet_to_country.each do |subnet, country_initial|
if IPAddr.new(subnet).include?(IPAddr.new(ip))
country = country_initial
break
end
end
country
end
end