Puppet Class: network
- Inherits:
- ::network::params
- Defined in:
- manifests/init.pp
Overview
Class: network
This class installs and manages network
Parameters
- gateway
-
String. Optional. Default: undef The default gateway of your system
- hostname
-
String. Optional. Default: undef The hostname of your system
- ipv6_autoconf
-
String. Optional. Default: undef Globally disable / enable SLAAC for IPv6
- config_file_notify
-
String or Boolean. Optional. Default: ‘class_default’ Defines the content of the notify parameter on the resources which change network settings. The default string ‘class_default’ triggers network restart as defined by command service_restart_exec Set to undef or Boolean false to remove any notify, leave default value or set Boolean true to use class defaults, or define, as a string, the name(s) of the resources to notify. Ie: ‘Service’,
- config_file_require
-
String or Boolean. Optional. Default: undef, Defines the require argument of resources which handle network settings. The default is to leave this undefined and don’t force any dependency. Set the name of a resource to require (must be in the catalog) for custom need Ie: ‘Package’
- interfaces_hash
-
Hash. Default undef. The complete interfaces configuration (nested) hash Needs this structure:
-
First level: Interface name
-
Second level: Interface options (check network::interface for the available options)
If an hash is provided here, network::interface defines are declared with: create_resources(“network::interface”, $interfaces_hash, $default_interfaces_hash)
-
- default_interfaces_hash
-
Hash. Default {}. Values applied to all interfaces, if they don’t specify a more specific value themselves.
- routes_hash
-
Hash. Default undef. The complete routes configuration (nested) hash If an hash is provided here, network::route defines are declared with: create_resources(“network::route”, $routes_hash)
- mroutes_hash
-
Hash. Default undef. An hash of multiple route to be applied If an hash is provided here, network::mroute defines are declared with: create_resources(“network::mroute”, $mroutes_hash)
- rules_hash
-
Hash. Default undef. An hash of ip rules to be applied If an hash is provided here, network::rules defines are declared with: create_resources(“network::rules”, $rules_hash)
- tables_hash
-
Hash. Default undef. An hash of routing tables to be applied If an hash is provided here, network::routing_table defines are declared with: create_resources(“network::routing_table”, $tables_hash)
- confs_hash
-
Hash. Default undef. An hash of network:::conf defines to apply. If an hash is provided here, network::conf defines are declared with: create_resources(“network::conf”, $conf_hash)
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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'manifests/init.pp', line 83
class network (
$hostname = undef,
$interfaces_hash = undef,
$default_interfaces_hash = {},
$routes_hash = undef,
$mroutes_hash = undef,
$rules_hash = undef,
$tables_hash = undef,
$confs_hash = undef,
$hostname_file_template = "network/hostname-${::osfamily}.erb",
# Parameter used only on RedHat family
$gateway = undef,
$nozeroconf = undef,
$ipv6enable = undef,
$networking_ipv6 = undef,
$ipv6forwarding = undef,
$ipv6_autoconf = undef,
$ipv6_autotunnel = undef,
$ipv6_defaultgw = undef,
$ipv6_radvd_pidfile = undef,
# Stdmod commons
$package_name = $::network::params::package_name,
$package_ensure = 'present',
$service_restart_exec = $::network::params::service_restart_exec,
$config_file_path = $::network::params::config_file_path,
$config_file_require = undef,
$config_file_notify = 'class_default',
$config_file_source = undef,
$config_file_template = undef,
$config_file_content = undef,
$config_file_options_hash = { } ,
$config_file_per_interface = false,
$config_dir_path = $::network::params::config_dir_path,
$config_dir_source = undef,
$config_dir_purge = false,
$config_dir_recurse = true,
$dependency_class = undef,
$my_class = undef,
$monitor_class = undef,
$monitor_options_hash = { } ,
$firewall_class = undef,
$firewall_options_hash = { } ,
$scope_hash_filter = '(uptime.*|timestamp)',
$tcp_port = undef,
$udp_port = undef,
$hiera_merge = false,
$vlan = undef,
) inherits ::network::params {
# Hiera import
if( $hiera_merge == true ) {
$hiera_interfaces_hash = hiera_hash("${module_name}::interfaces_hash",undef)
$real_interfaces_hash = $hiera_interfaces_hash ? {
undef => $interfaces_hash,
default => $hiera_interfaces_hash,
}
$hiera_routes_hash = hiera_hash('network::routes_hash',undef)
$real_routes_hash = $hiera_routes_hash ? {
undef => $routes_hash,
default => $hiera_routes_hash,
}
$hiera_mroutes_hash = hiera_hash('network::mroutes_hash',undef)
$real_mroutes_hash = $hiera_mroutes_hash ? {
undef => $mroutes_hash,
default => $hiera_mroutes_hash,
}
$hiera_rules_hash = hiera_hash('network::rules_hash',undef)
$real_rules_hash = $hiera_rules_hash ? {
undef => $rules_hash,
default => $hiera_rules_hash,
}
$hiera_tables_hash = hiera_hash('network::tables_hash',undef)
$real_tables_hash = $hiera_tables_hash ? {
undef => $tables_hash,
default => $hiera_tables_hash,
}
$hiera_confs_hash = hiera_hash('network::confs_hash',undef)
$real_confs_hash = $hiera_confs_hash ? {
undef => $confs_hash,
default => $hiera_confs_hash,
}
}
else {
$real_interfaces_hash = $interfaces_hash
$real_routes_hash = $routes_hash
$real_mroutes_hash = $mroutes_hash
$real_rules_hash = $rules_hash
$real_tables_hash = $tables_hash
$real_confs_hash = $confs_hash
}
# Class variables validation and management
$config_file_owner = $::network::params::config_file_owner
$config_file_group = $::network::params::config_file_group
$config_file_mode = $::network::params::config_file_mode
$manage_config_file_content = $config_file_content ? {
undef => $config_file_template ? {
undef => undef,
default => template($config_file_template),
},
default => $config_file_content,
}
$manage_config_file_notify = $config_file_notify ? {
'class_default' => "Exec[${service_restart_exec}]",
'undef' => undef,
'' => undef,
undef => undef,
true => "Exec[${service_restart_exec}]",
false => undef,
default => $config_file_notify,
}
$manage_config_file_require = $config_file_require ? {
'class_default' => undef,
'undef' => undef,
'' => undef,
undef => undef,
true => undef,
false => undef,
default => $config_file_require,
}
$manage_hostname = pick($hostname, $::fqdn)
if $package_ensure == 'absent' {
$config_dir_ensure = absent
$config_file_ensure = absent
} else {
$config_dir_ensure = directory
$config_file_ensure = present
}
$manage_networking_ipv6 = $networking_ipv6 ? {
'yes' => 'yes',
'no' => 'no',
default => undef,
}
$manage_ipv6forwarding = $ipv6forwarding ? {
'yes' => 'yes',
'no' => 'no',
default => undef,
}
$manage_ipv6_autoconf = $ipv6_autoconf ? {
'yes' => 'yes',
'no' => 'no',
default => undef,
}
$manage_ipv6_autotunnel = $ipv6_autotunnel ? {
'yes' => 'yes',
'no' => 'no',
default => undef,
}
$manage_ipv6_defaultgw = $ipv6_defaultgw
$manage_ipv6_radvd_pidfile = $ipv6_radvd_pidfile
# Dependency class
if $dependency_class {
include $dependency_class
}
# Resources managed
if $package_name {
package { 'network':
ensure => $package_ensure,
name => $package_name,
}
Package['network'] -> Network::Interface<||>
Package['network'] -> Network::Route<||>
Package['network'] -> Network::Mroute<||>
Package['network'] -> Network::Rule<||>
Package['network'] -> Network::Routing_table<||>
}
if $config_file_path
and $config_file_source
or $manage_config_file_content {
file { 'network.conf':
ensure => $config_file_ensure,
path => $config_file_path,
mode => $config_file_mode,
owner => $config_file_owner,
group => $config_file_group,
source => $config_file_source,
content => $manage_config_file_content,
notify => $manage_config_file_notify,
require => $config_file_require,
}
}
if $config_dir_source {
file { 'network.dir':
ensure => $config_dir_ensure,
path => $config_dir_path,
source => $config_dir_source,
recurse => $config_dir_recurse,
purge => $config_dir_purge,
force => $config_dir_purge,
notify => $manage_config_file_notify,
require => $config_file_require,
}
}
# Command that triggers network restart
exec { $service_restart_exec :
command => $service_restart_exec,
alias => 'network_restart',
refreshonly => true,
path => '/bin:/sbin:/usr/bin:/usr/sbin',
}
# Create network interfaces from interfaces_hash, if present
if $real_interfaces_hash {
create_resources('network::interface', $real_interfaces_hash, $default_interfaces_hash)
}
if $real_routes_hash {
create_resources('network::route', $real_routes_hash)
}
if $real_mroutes_hash {
create_resources('network::mroute', $real_mroutes_hash)
}
if $real_rules_hash {
create_resources('network::rule', $real_rules_hash)
}
if $real_tables_hash {
create_resources('network::routing_table', $real_tables_hash)
}
if $real_confs_hash {
create_resources('network::conf', $real_confs_hash)
}
# Configure default gateway (On RedHat). Also hostname is set.
if $::osfamily == 'RedHat'
and ($::network::gateway
or $::network::hostname) {
file { '/etc/sysconfig/network':
ensure => $config_file_ensure,
mode => $config_file_mode,
owner => $config_file_owner,
group => $config_file_group,
content => template($network::hostname_file_template),
notify => $network::manage_config_file_notify,
}
case $::lsbmajdistrelease {
'7','8': {
exec { 'sethostname':
command => "/usr/bin/hostnamectl set-hostname ${manage_hostname}",
unless => "/usr/bin/hostnamectl status | grep 'Static hostname: ${manage_hostname}'",
}
}
default: {}
}
}
# Configure hostname (On Debian)
if $::osfamily == 'Debian'
and $hostname {
file { '/etc/hostname':
ensure => $config_file_ensure,
mode => $config_file_mode,
owner => $config_file_owner,
group => $config_file_group,
content => template($hostname_file_template),
notify => $manage_config_file_notify,
}
}
if $::osfamily == 'Suse' {
if $hostname {
file { '/etc/HOSTNAME':
ensure => $config_file_ensure,
mode => $config_file_mode,
owner => $config_file_owner,
group => $config_file_group,
content => inline_template("<%= @manage_hostname %>\n"),
notify => Exec['sethostname'],
}
exec { 'sethostname':
command => "/bin/hostname ${manage_hostname}",
unless => "/bin/hostname -f | grep ${manage_hostname}",
}
}
}
if $::osfamily == 'Solaris' {
if $hostname {
file { '/etc/nodename':
ensure => $config_file_ensure,
mode => $config_file_mode,
owner => $config_file_owner,
group => $config_file_group,
content => inline_template("<%= @manage_hostname %>\n"),
notify => Exec['sethostname'],
}
exec { 'sethostname':
command => "/usr/bin/hostname ${manage_hostname}",
unless => "/usr/bin/hostname | /usr/bin/grep ${manage_hostname}",
}
}
}
# Extra classes
if $network::my_class {
include $network::my_class
}
if $network::monitor_class {
class { $network::monitor_class:
options_hash => $network::monitor_options_hash,
scope_hash => {}, # TODO: Find a good way to inject class' scope
}
}
if $firewall_class {
class { $firewall_class:
options_hash => $firewall_options_hash,
scope_hash => {},
}
}
}
|