-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathinit.pp
246 lines (235 loc) · 6.25 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# == Class: network
#
# This module manages Red Hat/Fedora network configuration.
#
# === Parameters:
#
# None
#
# === Actions:
#
# Defines the network service so that other resources can notify it to restart.
#
# === Sample Usage:
#
# include '::network'
#
# === Authors:
#
# Mike Arnold <[email protected]>
#
# === Copyright:
#
# Copyright (C) 2011 Mike Arnold, unless otherwise noted.
#
class network {
# Only run on RedHat derived systems.
case $::osfamily {
'RedHat': { }
default: {
fail('This network module only supports RedHat-based systems.')
}
}
service { 'network':
ensure => 'running',
enable => true,
hasrestart => true,
hasstatus => true,
provider => 'redhat',
}
} # class network
# == Definition: network_if_base
#
# This definition is private, i.e. it is not intended to be called directly
# by users. It can be used to write out the following device files:
# /etc/sysconfig/networking-scripts/ifcfg-eth
# /etc/sysconfig/networking-scripts/ifcfg-eth:alias
# /etc/sysconfig/networking-scripts/ifcfg-bond(master)
#
# === Parameters:
#
# $ensure - required - up|down
# $ipaddress - optional
# $netmask - optional
# $macaddress - required
# $manage_hwaddr - optional - defaults to true
# $gateway - optional
# $noaliasrouting - optional - defaults to false
# $bootproto - optional
# $userctl - optional - defaults to false
# $mtu - optional
# $dhcp_hostname - optional
# $persistent_dhclient - optional - defaults to false
# $ethtool_opts - optional
# $bonding_opts - optional
# $isalias - optional
# $peerdns - optional
# $dns1 - optional
# $dns2 - optional
# $domain - optional
# $bridge - optional
# $scope - optional
# $linkdelay - optional
# $check_link_down - optional
# $flush - optional
# $zone - optional
# $metric - optional
# $defroute - optional
# $promisc - optional - defaults to false
# $restart - optional - defaults to true
# $arpcheck - optional - defaults to true
#
# === Actions:
#
# Performs 'service network restart' after any changes to the ifcfg file and $restart parameter is 'true'.
#
# === TODO:
#
# HOTPLUG=yes|no
# WINDOW=
# SCOPE=
# SRCADDR=
# NOZEROCONF=yes
# DHCPRELEASE=yes|no|1|0
# DHCLIENT_IGNORE_GATEWAY=yes|no|1|0
# REORDER_HDR=yes|no
#
# === Authors:
#
# Mike Arnold <[email protected]>
#
# === Copyright:
#
# Copyright (C) 2011 Mike Arnold, unless otherwise noted.
#
define network_if_base (
$ensure,
$macaddress,
$ipaddress = undef,
$netmask = undef,
$manage_hwaddr = true,
$gateway = undef,
$noaliasrouting = false,
$ipv6address = undef,
$ipv6gateway = undef,
$ipv6init = false,
$ipv6autoconf = false,
$ipv6secondaries = undef,
$bootproto = 'none',
$userctl = false,
$mtu = undef,
$dhcp_hostname = undef,
$persistent_dhclient = false,
$ethtool_opts = undef,
$bonding_opts = undef,
$isalias = false,
$peerdns = false,
$ipv6peerdns = false,
$dns1 = undef,
$dns2 = undef,
$domain = undef,
$bridge = undef,
$linkdelay = undef,
$scope = undef,
$check_link_down = false,
$flush = false,
$defroute = undef,
$zone = undef,
$metric = undef,
$promisc = false,
$restart = true,
$arpcheck = true,
) {
# Validate our booleans
validate_bool($noaliasrouting)
validate_bool($userctl)
validate_bool($isalias)
validate_bool($peerdns)
validate_bool($ipv6init)
validate_bool($ipv6autoconf)
validate_bool($ipv6peerdns)
validate_bool($check_link_down)
validate_bool($manage_hwaddr)
validate_bool($flush)
validate_bool($promisc)
validate_bool($restart)
validate_bool($arpcheck)
# Validate our regular expressions
$states = [ '^up$', '^down$' ]
validate_re($ensure, $states, '$ensure must be either "up" or "down".')
include '::network'
$interface = $name
# Normalize $persistent_dhclient value
$persistent_dhclient_real = bool2num($persistent_dhclient)
# Deal with the case where $dns2 is non-empty and $dns1 is empty.
if $dns2 {
if !$dns1 {
$dns1_real = $dns2
$dns2_real = undef
} else {
$dns1_real = $dns1
$dns2_real = $dns2
}
} else {
$dns1_real = $dns1
$dns2_real = $dns2
}
if $isalias {
$onparent = $ensure ? {
'up' => 'yes',
'down' => 'no',
default => undef,
}
$iftemplate = template('network/ifcfg-alias.erb')
} else {
$onboot = $ensure ? {
'up' => 'yes',
'down' => 'no',
default => undef,
}
$iftemplate = template('network/ifcfg-eth.erb')
}
if $flush {
exec { 'network-flush':
user => 'root',
command => "ip addr flush dev ${interface}",
refreshonly => true,
subscribe => File["ifcfg-${interface}"],
before => Service['network'],
path => '/sbin:/usr/sbin',
}
}
file { "ifcfg-${interface}":
ensure => 'present',
mode => '0644',
owner => 'root',
group => 'root',
path => "/etc/sysconfig/network-scripts/ifcfg-${interface}",
content => $iftemplate,
}
if $restart {
File["ifcfg-${interface}"] {
notify => Service['network'],
}
}
} # define network_if_base
# == Definition: validate_ip_address
#
# This definition can be used to call is_ip_address on an array of ip addresses.
#
# === Parameters:
#
# None
#
# === Actions:
#
# Runs is_ip_address on the name of the define and fails if it is not a valid IP address.
#
# === Sample Usage:
#
# $ips = [ '10.21.30.248', '123:4567:89ab:cdef:123:4567:89ab:cdef' ]
# validate_ip_address { $ips: }
#
define validate_ip_address {
if ! is_ip_address($name) { fail("${name} is not an IP(v6) address.") }
} # define validate_ip_address