Merge pull request 'feat: add region fact' (#95) from neoloc/region_fact into develop
Reviewed-on: unkinben/puppet-prod#95
This commit is contained in:
commit
ff83769ffc
28
site/profiles/lib/facter/region.rb
Normal file
28
site/profiles/lib/facter/region.rb
Normal file
@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# set region based on the subnet
|
||||
|
||||
Facter.add('region') do
|
||||
setcode do
|
||||
# use facts['networking']['ip']to find the promary IP address
|
||||
ip = Facter.value(:networking)['ip']
|
||||
|
||||
# subnet to region mapping
|
||||
subnet_to_region = {
|
||||
'198.18.17.0/24' => 'au-drw-1'
|
||||
}
|
||||
|
||||
require 'ipaddr'
|
||||
|
||||
# Find the region for the IP
|
||||
region = 'lost' # default to 'lost' if no region matches
|
||||
subnet_to_region.each do |subnet, region_name|
|
||||
if IPAddr.new(subnet).include?(IPAddr.new(ip))
|
||||
region = region_name
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
region
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user