-
Notifications
You must be signed in to change notification settings - Fork 80
/
init.pp
161 lines (148 loc) · 4.99 KB
/
init.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
# Manage an ISC DHCP server
class dhcp (
Array[String] $dnsdomain = $dhcp::params::dnsdomain,
Array[String] $nameservers = ['8.8.8.8', '8.8.4.4'],
Boolean $failover = false,
Optional[Boolean] $bootp = undef,
Array[String] $ntpservers = [],
Optional[Array[String]] $interfaces = undef,
String $interface = 'NOTSET',
Integer[0] $default_lease_time = 43200,
Integer[0] $max_lease_time = 86400,
String $dnskeyname = 'rndc-key',
Optional[String] $dnsupdatekey = undef,
Optional[String] $dnsupdateserver = undef,
Boolean $omapi = true,
Optional[String] $omapi_name = undef,
String $omapi_algorithm = 'HMAC-MD5',
Optional[String] $omapi_key = undef,
Optional[String] $pxeserver = undef,
String $pxefilename = $dhcp::params::pxefilename,
Optional[Integer[0]] $mtu = undef,
Hash[String, String] $bootfiles = $dhcp::params::bootfiles,
String $logfacility = 'local7',
Boolean $dhcp_monitor = true,
Stdlib::Absolutepath $dhcp_dir = $dhcp::params::dhcp_dir,
String $packagename = $dhcp::params::packagename,
String $servicename = $dhcp::params::servicename,
$option_static_route = undef,
Variant[Array[String], Optional[String]] $options = undef,
Boolean $authoritative = false,
String $dhcp_root_group = $dhcp::params::root_group,
Boolean $ddns_updates = false,
Optional[String] $ddns_domainname = undef,
Optional[String] $ddns_rev_domainname = undef,
Enum['none', 'interim', 'standard'] $ddns_update_style = 'interim',
Hash[String, Hash] $pools = {},
Hash[String, Hash] $hosts = {},
Variant[Array[String], Optional[String]] $includes = undef,
String $config_comment = 'dhcpd.conf',
) inherits dhcp::params {
# In case people set interface instead of interfaces work around
# that. If they set both, use interfaces and the user is a unwise
# and deserves what they get.
if $interface != 'NOTSET' and $interfaces == undef {
$dhcp_interfaces = [ $interface ]
} elsif $interface == 'NOTSET' and $interfaces == undef {
fail ("You need to set \$interfaces in ${module_name}")
} else {
$dhcp_interfaces = $interfaces
}
# See https://tools.ietf.org/html/draft-ietf-dhc-failover-12 for why BOOTP is
# not supported in the failover protocol. Relay agents *can* be made to work
# so $bootp can be explicitly set to true to override this default.
if $bootp == undef {
$bootp_real = !$failover
} else {
$bootp_real = $bootp
}
$dnsupdateserver_real = pick($dnsupdateserver, $nameservers[0])
package { $packagename:
ensure => installed,
}
file { $dhcp_dir:
mode => '0755',
require => Package[$packagename],
}
# Only debian and ubuntu have this style of defaults for startup.
case $facts['osfamily'] {
'Debian': {
file{ '/etc/default/isc-dhcp-server':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
before => Package[$packagename],
notify => Service[$servicename],
content => template('dhcp/debian/default_isc-dhcp-server'),
}
}
'RedHat': {
if versioncmp($facts['operatingsystemmajrelease'], '7') >= 0 {
include systemd
systemd::dropin_file { 'interfaces.conf':
unit => 'dhcpd.service',
content => template('dhcp/redhat/systemd-dropin.conf.erb'),
}
} else {
file { '/etc/sysconfig/dhcpd':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
before => Package[$packagename],
notify => Service[$servicename],
content => template('dhcp/redhat/sysconfig-dhcpd'),
}
}
}
/^(FreeBSD|DragonFly)$/: {
$interfaces_line = join($dhcp_interfaces, ' ')
augeas { 'set listen interfaces':
context => '/files/etc/rc.conf',
changes => "set dhcpd_ifaces '\"${interfaces_line}\"'",
before => Package[$packagename],
notify => Service[$servicename],
}
}
default: {
}
}
concat { "${dhcp_dir}/dhcpd.conf":
owner => 'root',
group => $dhcp_root_group,
mode => '0644',
require => Package[$packagename],
notify => Service[$servicename],
}
concat::fragment { 'dhcp.conf+01_main.dhcp':
target => "${dhcp_dir}/dhcpd.conf",
content => template('dhcp/dhcpd.conf.erb'),
order => '01',
}
if $includes {
concat::fragment { 'dhcp.conf+20_includes':
target => "${dhcp_dir}/dhcpd.conf",
content => template('dhcp/dhcpd.conf.includes.erb'),
order => '20',
}
}
concat { "${dhcp_dir}/dhcpd.hosts":
owner => 'root',
group => $dhcp_root_group,
mode => '0644',
require => Package[$packagename],
notify => Service[$servicename],
}
concat::fragment { 'dhcp.hosts+01_main.hosts':
target => "${dhcp_dir}/dhcpd.hosts",
content => "# static DHCP hosts\n",
order => '01',
}
create_resources('dhcp::pool', $pools)
create_resources('dhcp::host', $hosts)
service { $servicename:
ensure => running,
enable => true,
}
}