forked from camptocamp/puppet-bind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzone.pp
175 lines (158 loc) · 5.49 KB
/
zone.pp
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
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
167
168
169
170
171
172
173
174
175
# = Definition: bind::zone
#
# Creates a valid Bind9 zone.
#
# Arguments:
# *$zone_type*: String. Specify if the zone is master/slave/forward. Default master
# *$transfer_source*: IPv4 address. Source IP to bind to when requesting a transfer (slave only)
# *$zone_ttl*: Time period. Time to live for your zonefile (master only)
# *$zone_contact*: Valid contact record (master only)
# *$zone_refresh*: Time period. Time between each slave refresh (master only)
# *$zone_retry*: Time period. Time between each slave retry (master only)
# *$zone_expiracy*: Time period. Slave expiracy time (master only)
# *$zone_ns*: Valid NS for this zone (master only)
# *$zone_xfers*: IPs. Valid xfers for zone (master only)
# *$zone_masters*: IPs. Valid master for this zone (slave only)
# *$zone_forwarders*: IPs. Valid forwarders for this zone (forward only)
# *$zone_origin*: The origin of the zone
# *$zone_notify*: IPs to use for also-notify entry
#
define bind::zone (
$ensure = present,
$is_dynamic = false,
$allow_update = [],
$transfer_source = undef,
$zone_type = 'master',
$zone_ttl = undef,
$zone_contact = undef,
$zone_refresh = '3h',
$zone_retry = '1h',
$zone_expiracy = '1w',
$zone_ns = [],
$zone_xfers = undef,
$zone_masters = undef,
$zone_forwarders = undef,
$zone_origin = undef,
$zone_notify = undef,
$is_slave = false,
$is_reverse = false,
) {
include ::bind::params
validate_string($ensure)
validate_re($ensure, ['present', 'absent'],
"\$ensure must be either 'present' or 'absent', got '${ensure}'")
validate_bool($is_slave)
validate_bool($is_dynamic)
validate_array($allow_update)
validate_string($transfer_source)
validate_string($zone_type)
validate_string($zone_ttl)
validate_string($zone_contact)
validate_string($zone_refresh)
validate_string($zone_retry)
validate_string($zone_expiracy)
validate_hash($zone_ns)
validate_bool($is_reverse)
validate_string($zone_origin)
# add backwards support for is_slave parameter
if ($is_slave) and ($zone_type == 'master') {
warning('$is_slave is deprecated. You should set $zone_type = \'slave\'')
$int_zone_type = 'slave'
} else {
$int_zone_type = $zone_type
}
if ($int_zone_type != 'master' and $is_dynamic) {
fail "Zone '${name}' cannot be ${int_zone_type} AND dynamic!"
}
if ($transfer_source and $int_zone_type != 'slave') {
fail "Zone '${name}': transfer_source can be set only for slave zones!"
}
concat::fragment {"named.local.zone.${name}":
ensure => $ensure,
target => "${bind::params::config_base_dir}/${bind::params::named_local_name}",
content => "include \"${bind::params::zones_directory}/${name}.conf\";\n",
notify => Exec['reload bind9'],
require => Package['bind9'],
}
case $ensure {
'present': {
concat {"${bind::params::zones_directory}/${name}.conf":
owner => root,
group => root,
mode => '0644',
notify => Exec['reload bind9'],
}
concat::fragment {"bind.zones.${name}":
ensure => $ensure,
target => "${bind::params::zones_directory}/${name}.conf",
notify => Exec['reload bind9'],
require => Package['bind9'],
}
case $int_zone_type {
'master': {
validate_re($zone_contact, '^\S+$', "Wrong contact value for ${name}!")
#validate_slength($zone_ns, 255, 3)
validate_re($zone_ttl, '^\d+$', "Wrong ttl value for ${name}!")
$conf_file = $is_dynamic? {
true => "${bind::params::dynamic_directory}/${name}.conf",
default => "${bind::params::pri_directory}/${name}.conf",
}
$require = $is_dynamic? {
true => Bind::Key[$allow_update],
default => undef,
}
if $is_dynamic {
file {$conf_file:
owner => root,
group => $bind::params::bind_group,
mode => '0664',
replace => false,
content => template('bind/zone-header.erb'),
notify => Exec['reload bind9'],
require => [Package['bind9'], $require],
}
} else {
concat {$conf_file:
owner => root,
group => $bind::params::bind_group,
mode => '0664',
notify => Exec['reload bind9'],
require => Package['bind9'],
}
concat::fragment {"00.bind.${name}":
ensure => $ensure,
target => $conf_file,
content => template('bind/zone-header.erb'),
}
}
Concat::Fragment["bind.zones.${name}"] {
content => template('bind/zone-master.erb'),
}
file {"${bind::params::pri_directory}/${name}.conf.d":
ensure => absent,
}
}
'slave': {
Concat::Fragment["bind.zones.${name}"] {
content => template('bind/zone-slave.erb'),
}
}
'forward': {
Concat::Fragment["bind.zones.${name}"] {
content => template('bind/zone-forward.erb'),
}
}
default: { fail("Zone type '${int_zone_type}' not supported.") }
}
}
'absent': {
file {"${bind::params::pri_directory}/${name}.conf":
ensure => absent,
}
file {"${bind::params::zones_directory}/${name}.conf":
ensure => absent,
}
}
default: {}
}
}