Files
puppet-prod/site/profiles/manifests/dns/base.pp
T
unkinben 3e807201ee
ci/woodpecker/pr/ruby-validate Pipeline was successful
ci/woodpecker/pr/puppet-lint Pipeline was successful
ci/woodpecker/pr/yamllint Pipeline was successful
ci/woodpecker/pr/bolt-validate Pipeline was successful
ci/woodpecker/pr/erb-validate Pipeline was successful
ci/woodpecker/pr/epp-validate Pipeline was successful
ci/woodpecker/pr/puppet-validate Pipeline was successful
ci/woodpecker/pr/ruby-check Pipeline was successful
dns: nsupdate host records to the authoritative server
Replaces the exported-resources -> puppet DNS master zone-file flow with
per-host RFC2136 dynamic updates against the k8s bind-authoritative write
endpoint (198.18.200.9), so the master no longer manages zone files.

- add profiles::dns::updater: assembles the host's records into a concat
  file and runs nsupdate via a systemd .path unit that watches it; the
  dns-update script sends only the delta and deletes removed records
- switch profiles::dns::record to write local concat fragments
  (zone|name|type|ttl|value) instead of exporting to the master
- include profiles::dns::updater from profiles::dns::base (all nodes)
- inert until profiles::dns::updater::key_secret (TSIG) is set in eyaml
- hiera: updater server/key_name/algorithm in common.yaml
2026-07-05 16:11:46 +10:00

90 lines
2.7 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 (provides nsupdate)
include bind::updater
# assemble the host's DNS records and nsupdate them to the authoritative server
include profiles::dns::updater
# if ns_role is set, find all hosts matching that enc_role
$nameserver_array = $ns_role ? {
undef => $nameservers,
default => $use_ns ? {
'all' => puppetdb_query(
"facts[certname,value] {
name = 'networking' and
certname in nodes[certname] { facts.enc_role = '${ns_role}' }
}"
).map |$fact| { $fact['value']['ip'] },
'region' => puppetdb_query(
"facts[certname,value] {
name = 'networking' and
certname in nodes[certname] {
facts.enc_role = '${ns_role}' and facts.region = '${facts['region']}'
}
}"
).map |$fact| { $fact['value']['ip'] },
'country' => puppetdb_query(
"facts[certname,value] {
name = 'networking' and
certname in nodes[certname] {
facts.enc_role = '${ns_role}' and facts.country = '${facts['country']}'
}
}"
).map |$fact| { $fact['value']['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, lo, docker0 and anycast addresses
if $data['ip'] and $interface != 'lo' and $interface != 'docker0' and $interface !~ /^anycast[0-9]$/ and $interface !~ /^cilium_/ {
# 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}",
}
}
}
}
}