Puppet Class: dns
- Inherits:
- dns::params
- Defined in:
- manifests/init.pp
Overview
Class: dns
Using custom types untill next stdlib release
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'manifests/init.pp', line 4
class dns (
Optional[String] $default_tsig_name = 'NOKEY',
Array[String] $default_masters = [],
Array[String] $default_provide_xfrs = [],
Optional[Tea::Ipv4] $default_ipv4 = $::dns::params::default_ipv4,
Optional[Tea::Ipv6] $default_ipv6 = $::dns::params::default_ipv6,
Integer[1,256] $server_count = $::dns::params::server_count,
Pattern[/^(nsd|knot)$/] $daemon = $::dns::params::daemon,
String $nsid = $::dns::params::nsid,
String $identity = $::dns::params::identity,
Array[Tea::Ip_address] $ip_addresses = $::dns::params::ip_addresses,
Array[String] $imports = [],
Array[String] $exports = [],
Pattern[/^(present|absent)$/] $ensure = 'present',
Tea::Port $port = 53,
Hash[String, Dns::Zone] $zones = {},
Hash $files = {},
Hash $tsigs = {},
Hash $remotes = {},
Boolean $enable_nagios = false,
) inherits dns::params {
if $daemon == 'nsd' {
$nsd_enable = true
$knot_enable = false
file {'/usr/local/bin/dns-control':
ensure => link,
target => '/usr/sbin/nsd-control',
}
} else {
$nsd_enable = false
$knot_enable = true
file {'/usr/local/bin/dns-control':
ensure => link,
target => '/usr/sbin/knotc',
}
}
# Currently nsd and knot dont support signed
# and signed policy so we remove them
$_zones = $zones.reduce({}) |$reduce_store, $value| {
$zone = $value[0]
$config = $value[1].filter |$key| { $key[0] !~ /^signe/ }
$tmp = merge($reduce_store, {$zone => $config})
$tmp
}
$imports.each |String $import| {
Knot::Tsig <<| tag == "dns__${import}" |>>
Knot::Remote <<| tag == "dns__${import}" |>>
Nsd::Tsig <<| tag == "dns__${import}" |>>
Nsd::Remote <<| tag == "dns__${import}" |>>
Dns::Tsig <<| tag == "dns__${import}_slave_tsig" |>>
Dns::Remote <<| tag == "dns__${import}_slave_remote" |>>
}
$exports.each |String $export| {
if $default_tsig_name != 'NOKEY' {
$_export_tsig = "dns__export_${export}_${default_tsig_name}"
@@knot::tsig {$_export_tsig:
algo => pick($tsigs[$default_tsig_name]['algo'], 'hmac-sha256'),
data => $tsigs[$default_tsig_name]['data'],
key_name => $default_tsig_name,
tag => "dns__${export}",
}
@@nsd::tsig {$_export_tsig:
algo => pick($tsigs[$default_tsig_name]['algo'], 'hmac-sha256'),
data => $tsigs[$default_tsig_name]['data'],
key_name => $default_tsig_name,
tag => "dns__${export}",
}
} else {
$_export_tsig = undef
}
@@knot::remote {"dns__export_${export}_${::fqdn}":
address4 => $default_ipv4,
address6 => $default_ipv6,
tsig => $_export_tsig,
tsig_name => $default_tsig_name,
port => $port,
tag => "dns__${export}",
}
@@nsd::remote {"dns__export_${export}_${::fqdn}":
address4 => $default_ipv4,
address6 => $default_ipv6,
tsig => $_export_tsig,
tsig_name => $default_tsig_name,
port => $port,
tag => "dns__${export}",
}
}
if $ensure == 'present' {
class { '::nsd':
enable => $nsd_enable,
ip_addresses => $ip_addresses,
server_count => $server_count,
nsid => $nsid,
identity => $identity,
default_tsig_name => $default_tsig_name,
default_masters => $default_masters,
default_provide_xfrs => $default_provide_xfrs,
files => $files,
tsigs => $tsigs,
zones => $_zones,
remotes => $remotes,
imports => $imports,
exports => $exports,
}
class { '::knot':
enable => $knot_enable,
ip_addresses => $ip_addresses,
server_count => $server_count,
nsid => $nsid,
identity => $identity,
default_tsig_name => $default_tsig_name,
default_masters => $default_masters,
default_provide_xfrs => $default_provide_xfrs,
files => $files,
tsigs => $tsigs,
zones => $_zones,
remotes => $remotes,
imports => $imports,
exports => $exports,
}
# when switching from one deamon to the other we need to make sure
# the old one is stoped before the new one starts
if $daemon == 'nsd' {
Service <| title == $::knot::service_name |> {
before => Service[$::nsd::service_name]
}
} else {
Service <| title == $::nsd::service_name |> {
before => Service[$::knot::service_name]
}
}
}
if $enable_nagios {
$_ip_addresses_list = join($ip_addresses, ' ')
$zones.each |String $zone, Hash $config| {
if has_key($config, 'masters') {
$_masters = flatten($config['masters'].map |String $master| {
delete_undef_values(
[$remotes[$master]['address4'], $remotes[$master]['address6']]
)
})
} else {
$_masters = flatten($default_masters.map |String $master| {
delete_undef_values(
[$remotes[$master]['address4'], $remotes[$master]['address6']]
)
})
}
if ! empty($_masters) {
$master_check_args = join($_masters, ' ')
@@nagios_service{ "${::fqdn}_DNS_ZONE_MASTERS_${zone}":
ensure => present,
use => 'generic-service',
host_name => $::fqdn,
service_description => "DNS_ZONE_MASTERS_${zone}",
check_command => "check_nrpe_args!check_dns!${zone}!${master_check_args}!${_ip_addresses_list}",
}
}
}
}
}
|