1
2
3
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
|
# @param config_file
# Bind9 configuration file
# @param directory
# Maps to bind9 directory. Base for all relative paths.
# @param checkzone
# Absolute path to named-checkzone binary
# @param checkconf
# Absolute path to named-checkconf binary
# @param packagename
# Name of the bind9 system package
# @param manage_package
# Should the bind9 system package be managed by this module.
# @param rndc
# Absolute path to rndc binary
# @param keys
# Dns::Key resources to create
# @param zones
# Dns::Zones resources to create
# @param rndc_key_file
# Location of rndc key. Note that this doesn't change where it ends up, but rather were we expect it to end up.
# Key will be generated through `rndc-confgen -a`.
# @param servicename
# Name of the system service to manage
# @param rndc_confgen
# Path to rndc-confgen binary
class dns (
String $config_file = '/etc/named.conf',
# String $config_dir = '/etc/named.d',
String $rndc_key_file = '/etc/rndc.key',
String $directory = '/var/named',
String $checkzone = '/usr/bin/named-checkzone',
String $checkconf = '/usr/bin/named-checkconf',
Hash[String, Dns::Keyentry] $keys = [],
Hash[String, Dns::Zoneentry] $zones = [],
String $packagename = 'bind9',
Boolean $manage_package = true,
String $servicename = 'named',
String $rndc = '/usr/bin/rndc',
String $rndc_confgen = '/usr/bin/rndc-confgen',
) {
$zone_directory = "${directory}/zones"
$jnl_directory = "${directory}/journal"
file { $zone_directory:
ensure => directory,
recurse => true,
purge => true,
}
file { $jnl_directory:
ensure => directory,
}
if $manage_package {
package { $packagename:
ensure => installed,
}
}
service { $servicename:
ensure => running,
enable => true,
}
notify {
'zones': message => "${zones}" ;
'keys': message => "${keys}" ;
}
# create_resources(dns::key, $keys)
# create_resources(dns::zone, $zones)
# file { $config_dir:
# ensure => directory,
# recurse => true,
# }
exec { 'Setup rndc key':
cmd => [$rndc_confgen, '-a'],
creates => $rndc_key_file,
}
concat { $config_file:
ensure_newline => true,
warn => '; File managed by Puppet. Local changes WILL be overwritter',
validate_cmd => "${checkconf} %",
notify => Service[$servicename],
}
concat::fragment { 'named.conf main configuration':
target => $config_file,
content => epp("${module_name}/named.conf.epp"),
}
concat::fragment { 'named.conf rndc configuration':
target => $config_file,
content => epp("${module_name}/named-rndc.conf.epp"),
}
}
|