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
- 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)
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 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 |
# File 'manifests/init.pp', line 56
class network (
$hostname = undef,
$interfaces_hash = undef,
$default_interfaces_hash = {},
$routes_hash = undef,
$mroutes_hash = undef,
$rules_hash = undef,
$tables_hash = undef,
$hostname_file_template = "network/hostname-${::osfamily}.erb",
# Parameter used only on RedHat family
$gateway = undef,
$nozeroconf = undef,
$ipv6enable = 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,
) 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,
}
}
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
}
# 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,
default => $config_file_notify,
}
$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
}
# 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)
}
# 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': {
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 => {},
}
}
}
|