feat: add/update location facts
- add country fact, change region to exclude country string
This commit is contained in:
parent
7431ebf51c
commit
dbec0222b3
28
site/profiles/lib/facter/country.rb
Normal file
28
site/profiles/lib/facter/country.rb
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# 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
|
||||||
@ -9,7 +9,7 @@ Facter.add('region') do
|
|||||||
|
|
||||||
# subnet to region mapping
|
# subnet to region mapping
|
||||||
subnet_to_region = {
|
subnet_to_region = {
|
||||||
'198.18.17.0/24' => 'au-drw-1'
|
'198.18.17.0/24' => 'drw1'
|
||||||
}
|
}
|
||||||
|
|
||||||
require 'ipaddr'
|
require 'ipaddr'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user