puppet-prod/site/profiles/manifests/dns/base.pp
Ben Vincent 19bc2002ee feat: deploy dns for all interfaces
feat: rework profiles::dns::client define

- reworked the profiles::dns::client to use new defaults
- removed static variables

feat: manage secondary interfaces

- define the primary interface for dns
- set primary interface as loopback0 for incus hosts
- add ip_sans for loopback interfaces
- add ssh principals for loopback interfaces
2025-05-11 16:00:20 +10:00

68 lines
2.0 KiB
Puppet

# profiles::dns::base
class profiles::dns::base (
Array $search = [],
Array $nameservers = ['198.18.13.12', '198.18.13.13'],
Optional[Enum[
'all',
'region',
'country'
]] $use_ns = undef,
String $primary_interface = $facts['networking']['primary'],
Optional[String] $ns_role = undef,
){
# install bind_utils
include bind::updater
# if ns_role is set, find all hosts matching that enc_role
$nameserver_array = $ns_role ? {
undef => $nameservers,
default => $use_ns ? {
'all' => query_nodes("enc_role='${ns_role}'", 'networking.ip'),
'region' => query_nodes("enc_role='${ns_role}' and region=${facts['region']}", 'networking.ip'),
'country' => query_nodes("enc_role='${ns_role}' and country=${facts['country']}", 'networking.ip'),
}
}
# if nameservers not returned from puppetdb, use default
$use_nameservers = empty($nameserver_array) ? {
true => $nameservers,
false => $nameserver_array,
}
# if search is undef, fallback to domainname from facts
if $search == [] {
$search_array = [$::facts['networking']['domain']]
}else{
$search_array = $search
}
# include resolvconf class
class { 'profiles::dns::resolvconf':
nameservers => sort($use_nameservers),
search_domains => sort($search_array),
}
# export dns records for client
$facts['networking']['interfaces'].each | $interface, $data | {
# exclude those without ipv4 address, and lo
if $data['ip'] and $interface != 'lo' {
# use defaults for the primary_interface
if $interface == $primary_interface {
profiles::dns::client {"${facts['networking']['fqdn']}-${interface}":
interface => $interface,
}
# update secondary interfaces
}else{
profiles::dns::client {"${facts['networking']['fqdn']}-${interface}":
interface => $interface,
hostname => "${facts['networking']['hostname']}-${interface}",
}
}
}
}
}