diff --git a/.fixtures.yml b/.fixtures.yml index a5de11f..aea64a2 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,10 @@ fixtures: repositories: - stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" + stdlib: + repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' + ref: '4.24.0' + ip: + repo: 'https://github.com/thrnio/puppet-ip.git' + ref: 'v1.0.0' symlinks: network: "#{source_dir}" diff --git a/.travis.yml b/.travis.yml index aee927e..28d5712 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,25 +14,10 @@ script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake matrix: fast_finish: true include: - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" - rvm: 2.1.9 env: PUPPET_GEM_VERSION="~> 4.0" - rvm: 2.4.1 env: PUPPET_GEM_VERSION="~> 5.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" - allow_failures: - - rvm: 2.4.1 - env: PUPPET_GEM_VERSION="~> 5.0" notifications: email: - github@razorsedge.org diff --git a/README.md b/README.md index 3d167aa..a64a68d 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ Bonded master interface - bridged (the corresponding network::bridge::* may also Bonded slave interface: network::bond::slave { 'eth1': - macaddress => $macaddress_eth1, + macaddress => $::networking['interfaces']['eth1']['mac'], ethtool_opts => 'autoneg off speed 1000 duplex full', master => 'bond0', } @@ -322,7 +322,7 @@ The Hiera naming substitutes underscore for any secondary double colons, i.e. sp Notes ----- -* Runs under Puppet 2.7 and later. +* Runs under Puppet 4.9 and later. * Only works with RedHat-ish systems. * Read /usr/share/doc/initscripts-*/sysconfig.txt for underlying details. * Read /usr/share/doc/kernel-doc-*/Documentation/networking/bonding.txt for underlying details. diff --git a/TODO.md b/TODO.md index ed1d4eb..ba8b3fc 100644 --- a/TODO.md +++ b/TODO.md @@ -30,7 +30,10 @@ and remove the interface. network::bond::dynamic { "bond2": slaves => [ "eth4", "eth7", ], - macaddress => [ $macaddress_eth4, $macaddress_eth7, ], + macaddress => [ + $::networking['interfaces']['eth4']['mac'], + $::networking['interfaces']['eth7']['mac'], + ], bonding_opts => "mode=active-backup", mtu => "1500", ethtool_opts => "speed 100 duplex full autoneg off", diff --git a/manifests/alias.pp b/manifests/alias.pp index a9e9e82..252989b 100644 --- a/manifests/alias.pp +++ b/manifests/alias.pp @@ -37,23 +37,18 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::alias ( - $ensure, - $ipaddress, - $netmask, - $gateway = undef, - $noaliasrouting = false, - $ipv6address = undef, - $ipv6gateway = undef, - $userctl = false, - $zone = undef, - $metric = undef, - $restart = true, + Enum['up', 'down'] $ensure, + IP::Address::V4::NoSubnet $ipaddress, + IP::Address::V4::NoSubnet $netmask, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Boolean $noaliasrouting = false, + Optional[IP::Address::V6] $ipv6address = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Boolean $userctl = false, + Optional[String] $zone = undef, + Optional[String] $metric = undef, + Boolean $restart = true, ) { - # Validate our data - if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") } - # Validate our booleans - validate_bool($noaliasrouting) - validate_bool($userctl) network_if_base { $title: ensure => $ensure, @@ -63,11 +58,8 @@ noaliasrouting => $noaliasrouting, ipv6address => $ipv6address, ipv6gateway => $ipv6gateway, - macaddress => '', bootproto => 'none', userctl => $userctl, - mtu => '', - ethtool_opts => '', isalias => true, zone => $zone, metric => $metric, diff --git a/manifests/alias/range.pp b/manifests/alias/range.pp index 4746d94..652401c 100644 --- a/manifests/alias/range.pp +++ b/manifests/alias/range.pp @@ -38,28 +38,16 @@ # Copyright (C) 2013 Mike Arnold, unless otherwise noted. # define network::alias::range ( - $ensure, - $ipaddress_start, - $ipaddress_end, - $clonenum_start, - $noaliasrouting = false, - $restart = true, - $netmask = false, - $broadcast = false, - $arpcheck = true, + Enum['up', 'down', 'absent'] $ensure, + IP::Address::V4::NoSubnet $ipaddress_start, + IP::Address::V4::NoSubnet $ipaddress_end, + String $clonenum_start, + Boolean $noaliasrouting = false, + Boolean $restart = true, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[IP::Address::V4::NoSubnet] $broadcast = undef, + Boolean $arpcheck = true, ) { - # Validate our data - if ! is_ip_address($ipaddress_start) { fail("${ipaddress_start} is not an IP address.") } - if ! is_ip_address($ipaddress_end) { fail("${ipaddress_end} is not an IP address.") } - if $netmask and !is_ip_address($netmask) { fail("${netmask} is not an IP address.") } - if $broadcast and !is_ip_address($broadcast) { fail("${broadcast} is not an IP address.") } - # Validate our booleans - validate_bool($noaliasrouting) - validate_bool($restart) - validate_bool($arpcheck) - # Validate our regular expressions - $states = [ '^up$', '^down$', '^absent$' ] - validate_re($ensure, $states, '$ensure must be either "up", "down", or "absent".') include '::network' @@ -82,7 +70,16 @@ owner => 'root', group => 'root', path => "/etc/sysconfig/network-scripts/ifcfg-${interface}-range${clonenum_start}", - content => template('network/ifcfg-alias-range.erb'), + content => epp("${module_name}/ifcfg-alias-range.epp", { + ipaddress_start => $ipaddress_start, + ipaddress_end => $ipaddress_end, + clonenum_start => $clonenum_start, + noaliasrouting => $noaliasrouting, + netmask => $netmask, + broadcast => $broadcast, + arpcheck => $arpcheck, + onparent => $onparent, + }), before => File["ifcfg-${interface}"], } diff --git a/manifests/bond.pp b/manifests/bond.pp index afc1a0a..e70312f 100644 --- a/manifests/bond.pp +++ b/manifests/bond.pp @@ -32,26 +32,17 @@ # Copyright (C) 2015 Jason Vervlied, unless otherwise noted. # define network::bond ( - $ensure, - $mtu = undef, - $ethtool_opts = undef, - $bonding_opts = 'miimon=100', - $zone = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + String $bonding_opts = 'miimon=100', + Optional[String] $zone = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', - macaddress => '', bootproto => 'none', - ipv6address => '', - ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, bonding_opts => $bonding_opts, @@ -61,10 +52,10 @@ # Only install "alias bondN bonding" on old OSs that support # /etc/modprobe.conf. - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemrelease { - /^[45]/: { + case $::os['release']['major'] { + /^[45]$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', changes => [ @@ -79,7 +70,7 @@ } } 'Fedora': { - case $::operatingsystemrelease { + case $::os['release']['major'] { /^(1|2|3|4|5|6|7|8|9|10|11)$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', diff --git a/manifests/bond/bridge.pp b/manifests/bond/bridge.pp index 5381e4c..43af328 100644 --- a/manifests/bond/bridge.pp +++ b/manifests/bond/bridge.pp @@ -34,26 +34,17 @@ # Copyright (C) 2013 Mike Arnold, unless otherwise noted. # define network::bond::bridge ( - $ensure, - $bridge, - $mtu = undef, - $ethtool_opts = undef, - $bonding_opts = 'miimon=100', - $restart = true, + Enum['up', 'down'] $ensure, + String $bridge, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + String $bonding_opts = 'miimon=100', + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', - macaddress => '', bootproto => 'none', - ipv6address => '', - ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, bonding_opts => $bonding_opts, @@ -63,10 +54,10 @@ # Only install "alias bondN bonding" on old OSs that support # /etc/modprobe.conf. - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemrelease { - /^[45]/: { + case $::os['release']['major'] { + /^[45]$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', changes => [ @@ -81,7 +72,7 @@ } } 'Fedora': { - case $::operatingsystemrelease { + case $::os['release']['major'] { /^(1|2|3|4|5|6|7|8|9|10|11)$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', diff --git a/manifests/bond/dynamic.pp b/manifests/bond/dynamic.pp index 65e3dbd..357a49f 100644 --- a/manifests/bond/dynamic.pp +++ b/manifests/bond/dynamic.pp @@ -36,28 +36,19 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::bond::dynamic ( - $ensure, - $mtu = undef, - $ethtool_opts = undef, - $bonding_opts = 'miimon=100', - $zone = undef, - $defroute = undef, - $metric = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + String $bonding_opts = 'miimon=100', + Optional[String] $zone = undef, + Optional[String] $defroute = undef, + Optional[String] $metric = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', - macaddress => '', bootproto => 'dhcp', - ipv6address => '', - ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, bonding_opts => $bonding_opts, @@ -69,10 +60,10 @@ # Only install "alias bondN bonding" on old OSs that support # /etc/modprobe.conf. - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemrelease { - /^[45]/: { + case $::os['release']['major'] { + /^[45]$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', changes => [ @@ -87,7 +78,7 @@ } } 'Fedora': { - case $::operatingsystemrelease { + case $::os['release']['major'] { /^(1|2|3|4|5|6|7|8|9|10|11)$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', diff --git a/manifests/bond/slave.pp b/manifests/bond/slave.pp index 8784584..e6b9037 100644 --- a/manifests/bond/slave.pp +++ b/manifests/bond/slave.pp @@ -26,7 +26,7 @@ # === Sample Usage: # # network::bond::slave { 'eth1': -# macaddress => $::macaddress_eth1, +# macaddress => $::networking['interfaces']['eth1']['mac'], # master => 'bond0', # } # @@ -39,24 +39,17 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::bond::slave ( - $master, - $macaddress = undef, - $ethtool_opts = undef, - $zone = undef, - $defroute = undef, - $metric = undef, - $restart = true, - $userctl = false, - $bootproto = undef, - $onboot = undef, + String $master, + Optional[Stdlib::MAC] $macaddress = undef, + Optional[String] $ethtool_opts = undef, + Optional[String] $zone = undef, + Optional[String] $defroute = undef, + Optional[String] $metric = undef, + Boolean $restart = true, + Boolean $userctl = false, + Optional[Network::If::Bootproto] $bootproto = undef, + Optional[String] $onboot = undef, ) { - # Validate our data - if $macaddress and ! is_mac_address($macaddress) { - fail("${macaddress} is not a MAC address.") - } - # Validate our booleans - validate_bool($restart) - validate_bool($userctl) include '::network' @@ -68,7 +61,18 @@ owner => 'root', group => 'root', path => "/etc/sysconfig/network-scripts/ifcfg-${interface}", - content => template('network/ifcfg-bond.erb'), + content => epp("${module_name}/ifcfg-bond.epp", { + interface => $interface, + macaddress => $macaddress, + master => $master, + ethtool_opts => $ethtool_opts, + defroute => $defroute, + zone => $zone, + metric => $metric, + bootproto => $bootproto, + onboot => $onboot, + userctl => $userctl, + }), before => File["ifcfg-${master}"], } diff --git a/manifests/bond/static.pp b/manifests/bond/static.pp index 0f28f52..5980254 100644 --- a/manifests/bond/static.pp +++ b/manifests/bond/static.pp @@ -41,47 +41,33 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::bond::static ( - $ensure, - $ipaddress = undef, - $netmask = undef, - $gateway = undef, - $mtu = undef, - $ethtool_opts = undef, - $bonding_opts = 'miimon=100', - $peerdns = false, - $ipv6init = false, - $ipv6address = undef, - $ipv6gateway = undef, - $ipv6peerdns = false, - $dns1 = undef, - $dns2 = undef, - $domain = undef, - $zone = undef, - $defroute = undef, - $metric = undef, - $restart = true, - $userctl = undef, + Enum['up', 'down'] $ensure, + Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + String $bonding_opts = 'miimon=100', + Boolean $peerdns = false, + Boolean $ipv6init = false, + Optional[IP::Address::V6] $ipv6address = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Boolean $ipv6peerdns = false, + Optional[IP::Address::NoSubnet] $dns1 = undef, + Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[String] $domain = undef, + Optional[String] $zone = undef, + Optional[String] $defroute = undef, + Optional[String] $metric = undef, + Boolean $restart = true, + Boolean $userctl = false, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - # Validate our data - if $ipaddress { - if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") } - } - if $ipv6address { - if ! is_ip_address($ipv6address) { fail("${ipv6address} is not an IPv6 address.") } - } - # Validate booleans - validate_bool($ipv6init) - validate_bool($ipv6peerdns) network_if_base { $title: ensure => $ensure, ipaddress => $ipaddress, netmask => $netmask, gateway => $gateway, - macaddress => '', bootproto => 'none', mtu => $mtu, ethtool_opts => $ethtool_opts, @@ -103,10 +89,10 @@ # Only install "alias bondN bonding" on old OSs that support # /etc/modprobe.conf. - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemrelease { - /^[45]/: { + case $::os['release']['major'] { + /^[45]$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', changes => [ @@ -121,7 +107,7 @@ } } 'Fedora': { - case $::operatingsystemrelease { + case $::os['release']['major'] { /^(1|2|3|4|5|6|7|8|9|10|11)$/: { augeas { "modprobe.conf_${title}": context => '/files/etc/modprobe.conf', diff --git a/manifests/bridge.pp b/manifests/bridge.pp index acb2102..1bf8ed3 100644 --- a/manifests/bridge.pp +++ b/manifests/bridge.pp @@ -5,10 +5,23 @@ # === Parameters: # # $ensure - required - up|down +# $ipaddress - optional +# $netmask - optional +# $gateway - optional +# $ipv6address - optional +# $ipv6gateway - optional +# $bootproto - optional - defaults to 'none' # $userctl - optional - defaults to false # $stp - optional - defaults to false # $delay - optional - defaults to 30 # $bridging_opts - optional +# $scope - optional +# $peerdns - optional - dedaults to false +# $ipv6init - optional - defaults to false +# $ipv6peerdns - optional - defaults to false +# $dns1 - optional +# $dns2 - optional +# $domain - optional # $restart - optional - defaults to true # # === Actions: @@ -33,48 +46,79 @@ # Copyright (C) 2013 Mike Arnold, unless otherwise noted. # define network::bridge ( - $ensure, - $userctl = false, - $stp = false, - $delay = '30', - $bridging_opts = undef, - $ipv6init = false, - $restart = true, + Enum['up', 'down'] $ensure, + Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[IP::Address::V6] $ipv6address = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Network::If::Bootproto $bootproto = 'none', + Boolean $userctl = false, + Boolean $stp = false, + String $delay = '30', + Optional[String] $bridging_opts = undef, + Optional[String] $scope = undef, + Boolean $peerdns = false, + Boolean $ipv6init = false, + Boolean $ipv6peerdns = false, + Optional[IP::Address::NoSubnet] $dns1 = undef, + Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[String] $domain = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - # Validate booleans - validate_bool($userctl) - validate_bool($stp) - validate_bool($ipv6init) - validate_bool($restart) ensure_packages(['bridge-utils']) include '::network' $interface = $name - $bootproto = 'none' - $ipaddress = undef - $netmask = undef - $gateway = undef - $ipv6address = undef - $ipv6gateway = undef - $onboot = $ensure ? { 'up' => 'yes', 'down' => 'no', default => undef, } + # 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 + } + file { "ifcfg-${interface}": ensure => 'present', mode => '0644', owner => 'root', group => 'root', path => "/etc/sysconfig/network-scripts/ifcfg-${interface}", - content => template('network/ifcfg-br.erb'), + content => epp("${module_name}/ifcfg-br.epp", { + interface => $interface, + bootproto => $bootproto, + onboot => $onboot, + ipv6init => $ipv6init, + userctl => $userctl, + delay => $delay, + stp => $stp, + bridging_opts => $bridging_opts, + ipaddress => $ipaddress, + netmask => $netmask, + gateway => $gateway, + ipv6address => $ipv6address, + ipv6gateway => $ipv6gateway, + scope => $scope, + peerdns => $peerdns, + ipv6peerdns => $ipv6peerdns, + dns1 => $dns1_real, + dns2 => $dns2_real, + domain => $domain, + }), require => Package['bridge-utils'], } diff --git a/manifests/bridge/dynamic.pp b/manifests/bridge/dynamic.pp index 729d464..42fd85e 100644 --- a/manifests/bridge/dynamic.pp +++ b/manifests/bridge/dynamic.pp @@ -36,52 +36,23 @@ # Copyright (C) 2013 Mike Arnold, unless otherwise noted. # define network::bridge::dynamic ( - $ensure, - $bootproto = 'dhcp', - $userctl = false, - $stp = false, - $delay = '30', - $bridging_opts = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Network::If::Bootproto $bootproto = 'dhcp', + Boolean $userctl = false, + Boolean $stp = false, + String $delay = '30', + Optional[String] $bridging_opts = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - # Validate booleans - validate_bool($userctl) - validate_bool($stp) - validate_bool($restart) - ensure_packages(['bridge-utils']) - - include '::network' - - $interface = $name - $ipaddress = undef - $netmask = undef - $gateway = undef - $ipv6address = undef - $ipv6gateway = undef - - $onboot = $ensure ? { - 'up' => 'yes', - 'down' => 'no', - default => undef, + network::bridge { $title: + ensure => $ensure, + bootproto => $bootproto, + userctl => $userctl, + stp => $stp, + delay => $delay, + bridging_opts => $bridging_opts, + restart => $restart, } - file { "ifcfg-${interface}": - ensure => 'present', - mode => '0644', - owner => 'root', - group => 'root', - path => "/etc/sysconfig/network-scripts/ifcfg-${interface}", - content => template('network/ifcfg-br.erb'), - require => Package['bridge-utils'], - } - - if $restart { - File["ifcfg-${interface}"] { - notify => Service['network'], - } - } } # define network::bridge::dynamic diff --git a/manifests/bridge/static.pp b/manifests/bridge/static.pp index 95b3a47..146cd3b 100644 --- a/manifests/bridge/static.pp +++ b/manifests/bridge/static.pp @@ -11,7 +11,7 @@ # $ipv6address - optional # $ipv6gateway - optional # $userctl - optional - defaults to false -# $peerdns - optional +# $peerdns - optional - defaults to false # $ipv6init - optional - defaults to false # $ipv6peerdns - optional - defaults to false # $dns1 - optional @@ -50,82 +50,47 @@ # Copyright (C) 2013 Mike Arnold, unless otherwise noted. # define network::bridge::static ( - $ensure, - $ipaddress = undef, - $netmask = undef, - $gateway = undef, - $ipv6address = undef, - $ipv6gateway = undef, - $bootproto = 'static', - $userctl = false, - $peerdns = false, - $ipv6init = false, - $ipv6peerdns = false, - $dns1 = undef, - $dns2 = undef, - $domain = undef, - $stp = false, - $delay = '30', - $bridging_opts = undef, - $scope = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[IP::Address::V6] $ipv6address = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Network::If::Bootproto $bootproto = 'static', + Boolean $userctl = false, + Boolean $peerdns = false, + Boolean $ipv6init = false, + Boolean $ipv6peerdns = false, + Optional[IP::Address::NoSubnet] $dns1 = undef, + Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[String] $domain = undef, + Boolean $stp = false, + String $delay = '30', + Optional[String] $bridging_opts = undef, + Optional[String] $scope = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - # Validate our data - if $ipaddress { - if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") } - } - if $ipv6address { - if ! is_ip_address($ipv6address) { fail("${ipv6address} is not an IPv6 address.") } - } - # Validate booleans - validate_bool($userctl) - validate_bool($stp) - validate_bool($ipv6init) - validate_bool($ipv6peerdns) - validate_bool($restart) - - ensure_packages(['bridge-utils']) - - include '::network' - - $interface = $name - # 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 + network::bridge { $title: + ensure => $ensure, + ipaddress => $ipaddress, + netmask => $netmask, + gateway => $gateway, + ipv6address => $ipv6address, + ipv6gateway => $ipv6gateway, + bootproto => $bootproto, + userctl => $userctl, + peerdns => $peerdns, + ipv6init => $ipv6init, + ipv6peerdns => $ipv6peerdns, + dns1 => $dns1, + dns2 => $dns2, + domain => $domain, + stp => $stp, + delay => $delay, + bridging_opts => $bridging_opts, + scope => $scope, + restart => $restart, } - $onboot = $ensure ? { - 'up' => 'yes', - 'down' => 'no', - default => undef, - } - - file { "ifcfg-${interface}": - ensure => 'present', - mode => '0644', - owner => 'root', - group => 'root', - path => "/etc/sysconfig/network-scripts/ifcfg-${interface}", - content => template('network/ifcfg-br.erb'), - require => Package['bridge-utils'], - } - - if $restart { - File["ifcfg-${interface}"] { - notify => Service['network'], - } - } } # define network::bridge::static diff --git a/manifests/global.pp b/manifests/global.pp index 9ff8c67..dec04f9 100644 --- a/manifests/global.pp +++ b/manifests/global.pp @@ -62,47 +62,30 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # class network::global ( - $hostname = undef, - $gateway = undef, - $gatewaydev = undef, - $ipv6gateway = undef, - $ipv6defaultdev = undef, - $nisdomain = undef, - $vlan = undef, - $ipv6networking = false, - $nozeroconf = undef, - $restart = true, - $requestreopen = true, + Optional[String] $hostname = undef, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[String] $gatewaydev = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Optional[String] $ipv6defaultdev = undef, + Optional[String] $nisdomain = undef, + Optional[Enum['yes', 'no']] $vlan = undef, + Boolean $ipv6networking = false, + Optional[Enum['yes', 'no']] $nozeroconf = undef, + Boolean $restart = true, + Boolean $requestreopen = true, ) { - # Validate our data - if $gateway { - if ! is_ip_address($gateway) { fail("${gateway} is not an IP address.") } - } - if $ipv6gateway { - if ! is_ip_address($ipv6gateway) { fail("${ipv6gateway} is not an IPv6 address.") } - } - - validate_bool($ipv6networking) - validate_bool($restart) - validate_bool($requestreopen) - - # Validate our regular expressions - if $vlan { - $states = [ '^yes$', '^no$' ] - validate_re($vlan, $states, '$vlan must be either "yes" or "no".') - } include '::network' - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemrelease { - /^[456]/: { $has_systemd = false } + case $::os['release']['major'] { + /^[456]$/: { $has_systemd = false } default: { $has_systemd = true } } } 'Fedora': { - case $::operatingsystemrelease { + case $::os['release']['major'] { /^(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17)$/: { $has_systemd = false } default: { $has_systemd = true } } @@ -118,13 +101,29 @@ } } + $effective_hostname = $hostname ? { + String => $hostname, + default => $::networking['fqdn'], + } + file { 'network.sysconfig': ensure => 'present', mode => '0644', owner => 'root', group => 'root', path => '/etc/sysconfig/network', - content => template('network/network.erb'), + content => epp("${module_name}/network.epp", { + ipv6networking => $ipv6networking, + ipv6gateway => $ipv6gateway, + ipv6defaultdev => $ipv6defaultdev, + hostname => $effective_hostname, + gateway => $gateway, + gatewaydev => $gatewaydev, + nisdomain => $nisdomain, + vlan => $vlan, + nozeroconf => $nozeroconf, + requestreopen => $requestreopen, + }), } if $restart { diff --git a/manifests/hiera.pp b/manifests/hiera.pp index 0d35044..3f5d50c 100644 --- a/manifests/hiera.pp +++ b/manifests/hiera.pp @@ -28,22 +28,33 @@ # class network::hiera { # Merge hashes from multiple hiera layers - $network_alias = hiera_hash('network::alias', undef) - $network_alias_range = hiera_hash('network::alias_range', undef) - $network_bond = hiera_hash('network::bond', undef) - $network_bond_bridge = hiera_hash('network::bond_bridge', undef) - $network_bond_dynamic = hiera_hash('network::bond_dynamic', undef) - $network_bond_slave = hiera_hash('network::bond_slave', undef) - $network_bond_static = hiera_hash('network::bond_static', undef) - $network_bridge = hiera_hash('network::bridge', undef) - $network_bridge_dynamic = hiera_hash('network::bridge_dynamic', undef) - $network_bridge_static = hiera_hash('network::bridge_static', undef) - $network_if = hiera_hash('network::if', undef) - $network_if_bridge = hiera_hash('network::if_bridge', undef) - $network_if_dynamic = hiera_hash('network::if_dynamic', undef) - $network_if_promisc = hiera_hash('network::if_promisc', undef) - $network_if_static = hiera_hash('network::if_static', undef) - $network_route = hiera_hash('network::route', undef) + $network_alias = lookup('network::alias', Optional[Hash], 'hash', undef) + $network_alias_range = lookup( + 'network::alias_range', Optional[Hash], 'hash', undef) + $network_bond = lookup('network::bond', Optional[Hash], 'hash', undef) + $network_bond_bridge = lookup( + 'network::bond_bridge', Optional[Hash], 'hash', undef) + $network_bond_dynamic = lookup( + 'network::bond_dynamic', Optional[Hash], 'hash', undef) + $network_bond_slave = lookup( + 'network::bond_slave', Optional[Hash], 'hash', undef) + $network_bond_static = lookup( + 'network::bond_static', Optional[Hash], 'hash', undef) + $network_bridge = lookup('network::bridge', Optional[Hash], 'hash', undef) + $network_bridge_dynamic = lookup( + 'network::bridge_dynamic', Optional[Hash], 'hash', undef) + $network_bridge_static = lookup( + 'network::bridge_static', Optional[Hash], 'hash', undef) + $network_if = lookup('network::if', Optional[Hash], 'hash', undef) + $network_if_bridge = lookup( + 'network::if_bridge', Optional[Hash], 'hash', undef) + $network_if_dynamic = lookup( + 'network::if_dynamic', Optional[Hash], 'hash', undef) + $network_if_promisc = lookup( + 'network::if_promisc', Optional[Hash], 'hash', undef) + $network_if_static = lookup( + 'network::if_static', Optional[Hash], 'hash', undef) + $network_route = lookup('network::route', Optional[Hash], 'hash', undef) if $network_alias { create_resources('network::alias', $network_alias) diff --git a/manifests/if.pp b/manifests/if.pp index 990a022..fc3874a 100644 --- a/manifests/if.pp +++ b/manifests/if.pp @@ -6,7 +6,7 @@ # # $ensure - required - up|down # $manage_hwaddr - optional - defaults to true -# $macaddress - optional - defaults to macaddress_$title +# $macaddress - optional - defaults to $::networking['interfaces'][$title]['mac'] # $userctl - optional - defaults to false # $mtu - optional # $ethtool_opts - optional @@ -34,45 +34,31 @@ # Copyright (C) 2017 Mike Arnold, unless otherwise noted. # define network::if ( - $ensure, - $manage_hwaddr = true, - $macaddress = undef, - $userctl = false, - $mtu = undef, - $ethtool_opts = undef, - $scope = undef, - $flush = false, - $zone = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Boolean $manage_hwaddr = true, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $userctl = false, + Variant[Integer, String, Undef] $mtu = undef, + Optional[String] $ethtool_opts = undef, + Optional[String] $scope = undef, + Boolean $flush = false, + Optional[String] $zone = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - if ! is_mac_address($macaddress) { + if $macaddress { + $macaddy = $macaddress + } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') - $macaddy = getvar("::macaddress_${title_clean}") - } else { - $macaddy = $macaddress + $macaddy = $::networking['interfaces'][$title_clean]['mac'] } - # Validate booleans - validate_bool($userctl) - validate_bool($manage_hwaddr) - validate_bool($flush) - validate_bool($restart) - network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', macaddress => $macaddy, manage_hwaddr => $manage_hwaddr, bootproto => 'none', - ipv6address => '', - ipv6gateway => '', userctl => $userctl, mtu => $mtu, ethtool_opts => $ethtool_opts, diff --git a/manifests/if/bridge.pp b/manifests/if/bridge.pp index b8eef61..b07a0e5 100644 --- a/manifests/if/bridge.pp +++ b/manifests/if/bridge.pp @@ -31,33 +31,18 @@ # Copyright (C) 2013 Alex Barbur, unless otherwise noted. # define network::if::bridge ( - $ensure, - $bridge, - $mtu = undef, - $ethtool_opts = undef, - $macaddress = undef, - $restart = true, + Enum['up', 'down'] $ensure, + String $bridge, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - - if $macaddress == undef { - $macaddy = '' # lint:ignore:empty_string_assignment - } - else { - $macaddy = $macaddress - } network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', - macaddress => $macaddy, + macaddress => $macaddress, bootproto => 'none', - ipv6address => '', - ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, bridge => $bridge, diff --git a/manifests/if/dynamic.pp b/manifests/if/dynamic.pp index 1bc4b16..e9ad72e 100644 --- a/manifests/if/dynamic.pp +++ b/manifests/if/dynamic.pp @@ -5,7 +5,7 @@ # === Parameters: # # $ensure - required - up|down -# $macaddress - optional - defaults to macaddress_$title +# $macaddress - optional - defaults to $::networking['interfaces'][$title]['mac'] # $manage_hwaddr - optional - defaults to true # $bootproto - optional - defaults to "dhcp" # $userctl - optional - defaults to false @@ -28,7 +28,7 @@ # # network::if::dynamic { 'eth2': # ensure => 'up', -# macaddress => $::macaddress_eth2, +# macaddress => $::networking['interfaces']['eth2']['mac'], # } # # network::if::dynamic { 'eth3': @@ -46,43 +46,33 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::if::dynamic ( - $ensure, - $macaddress = undef, - $manage_hwaddr = true, - $bootproto = 'dhcp', - $userctl = false, - $mtu = undef, - $dhcp_hostname = undef, - $ethtool_opts = undef, - $peerdns = false, - $linkdelay = undef, - $check_link_down = false, - $defroute = undef, - $zone = undef, - $metric = undef, - $restart = true, + Enum['up', 'down'] $ensure, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $manage_hwaddr = true, + Network::If::Bootproto $bootproto = 'dhcp', + Boolean $userctl = false, + Optional[String] $mtu = undef, + Optional[String] $dhcp_hostname = undef, + Optional[String] $ethtool_opts = undef, + Boolean $peerdns = false, + Optional[String] $linkdelay = undef, + Boolean $check_link_down = false, + Optional[String] $defroute = undef, + Optional[String] $zone = undef, + Optional[String] $metric = undef, + Boolean $restart = true, ) { - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - if ! is_mac_address($macaddress) { + if $macaddress { + $macaddy = $macaddress + } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') - $macaddy = getvar("::macaddress_${title_clean}") - } else { - $macaddy = $macaddress + $macaddy = $::networking['interfaces'][$title_clean]['mac'] } - # Validate booleans - validate_bool($userctl) - validate_bool($peerdns) - validate_bool($manage_hwaddr) network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', macaddress => $macaddy, manage_hwaddr => $manage_hwaddr, bootproto => $bootproto, diff --git a/manifests/if/promisc.pp b/manifests/if/promisc.pp index 291cdd6..105160e 100644 --- a/manifests/if/promisc.pp +++ b/manifests/if/promisc.pp @@ -5,7 +5,7 @@ # === Parameters: # # $ensure - required - up|down -# $macaddress - optional, defaults to macaddress_$title +# $macaddress - optional - defaults to $::networking['interfaces'][$title]['mac'] # $manage_hwaddr - optional - defaults to true # $bootproto - optional, defaults to undef ('none') # $userctl - optional @@ -41,41 +41,26 @@ # Copyright (C) 2015 Elyse Salberg, unless otherwise noted. # define network::if::promisc ( - $ensure, - $macaddress = undef, - $manage_hwaddr = true, - $bootproto = undef, - $userctl = false, - $mtu = undef, - $ethtool_opts = undef, - $restart = true, - $promisc = true, + Enum['up', 'down'] $ensure, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $manage_hwaddr = true, + Optional[Network::If::Bootproto] $bootproto = undef, + Boolean $userctl = false, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + Boolean $restart = true, + Boolean $promisc = true, ) { include '::network' $interface = $name - if ! is_mac_address($macaddress) { + if $macaddress { + $macaddy = $macaddress + } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') - $macaddy = getvar("::macaddress_${title_clean}") - } else { - $macaddy = $macaddress - } - - # Validate our regular expressions - $states = [ '^up$', '^down$' ] - validate_re($ensure, $states, '$ensure must be either "up" or "down".') - - # Validate booleans - validate_bool($userctl) - validate_bool($manage_hwaddr) - validate_bool($restart) - validate_bool($promisc) - - # Validate our data - if ! is_mac_address($macaddy) { - fail("${macaddy} is not a MAC address.") + $macaddy = $::networking['interfaces'][$title_clean]['mac'] } $onboot = $ensure ? { @@ -85,9 +70,9 @@ } if $promisc { - case $::operatingsystem { + case $::os['name'] { /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: { - case $::operatingsystemmajrelease { + case $::os['release']['major'] { '5': { $ifup_source = "puppet:///modules/${module_name}/promisc/ifup-local-promisc_5" $ifdown_source = "puppet:///modules/${module_name}/promisc/ifdown-local-promisc_5" @@ -144,14 +129,9 @@ network_if_base { $title: ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', macaddress => $macaddy, manage_hwaddr => $manage_hwaddr, bootproto => 'none', - ipv6address => '', - ipv6gateway => '', mtu => $mtu, ethtool_opts => $ethtool_opts, promisc => $promisc, diff --git a/manifests/if/static.pp b/manifests/if/static.pp index b32ccb6..3ea0dcb 100644 --- a/manifests/if/static.pp +++ b/manifests/if/static.pp @@ -12,7 +12,7 @@ # $ipv6init - optional - defaults to false # $ipv6gateway - optional # $manage_hwaddr - optional - defaults to true -# $macaddress - optional - defaults to macaddress_$title +# $macaddress - optional - defaults to $::networking['interfaces'][$title]['mac'] # $ipv6autoconf - optional - defaults to false # $userctl - optional - defaults to false # $mtu - optional @@ -40,7 +40,7 @@ # ensure => 'up', # ipaddress => '10.21.30.248', # netmask => '255.255.255.128', -# macaddress => $::macaddress_eth0, +# macaddress => $::networking['interfaces']['eth0']['mac'], # domain => 'is.domain.com domain.com', # ipv6init => true, # ipv6address => '123:4567:89ab:cdef:123:4567:89ab:cdef', @@ -56,45 +56,45 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::if::static ( - $ensure, - $ipaddress = undef, - $netmask = undef, - $gateway = undef, - $ipv6address = undef, - $ipv6init = false, - $ipv6gateway = undef, - $macaddress = undef, - $manage_hwaddr = true, - $ipv6autoconf = false, - $userctl = false, - $mtu = undef, - $ethtool_opts = undef, - $peerdns = false, - $ipv6peerdns = false, - $dns1 = undef, - $dns2 = undef, - $domain = undef, - $linkdelay = undef, - $scope = undef, - $flush = false, - $zone = undef, - $defroute = undef, - $metric = undef, - $restart = true, - $arpcheck = true, + Enum['up', 'down'] $ensure, + Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Optional[ + Variant[ + IP::Address::V6, + Tuple[IP::Address::V6, 1], + ] + ] $ipv6address = undef, + Boolean $ipv6init = false, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Optional[Stdlib::MAC] $macaddress = undef, + Boolean $manage_hwaddr = true, + Boolean $ipv6autoconf = false, + Boolean $userctl = false, + Optional[String] $mtu = undef, + Optional[String] $ethtool_opts = undef, + Boolean $peerdns = false, + Boolean $ipv6peerdns = false, + Optional[IP::Address::NoSubnet] $dns1 = undef, + Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[String] $domain = undef, + Optional[String] $linkdelay = undef, + Optional[String] $scope = undef, + Boolean $flush = false, + Optional[String] $zone = undef, + Optional[Enum['yes', 'no']] $defroute = undef, + Optional[String] $metric = undef, + Boolean $restart = true, + Boolean $arpcheck = true, ) { - # Validate our data - if $ipaddress { - if ! is_ip_address($ipaddress) { fail("${ipaddress} is not an IP address.") } - } + # Handle multiple IPv6 addresses if is_array($ipv6address) { if size($ipv6address) > 0 { - validate_ip_address { $ipv6address: } $primary_ipv6address = $ipv6address[0] $secondary_ipv6addresses = delete_at($ipv6address, 0) } } elsif $ipv6address { - if ! is_ip_address($ipv6address) { fail("${ipv6address} is not an IPv6 address.") } $primary_ipv6address = $ipv6address $secondary_ipv6addresses = undef } else { @@ -102,22 +102,13 @@ $secondary_ipv6addresses = undef } - if ! is_mac_address($macaddress) { + if $macaddress { + $macaddy = $macaddress + } else { # Strip off any tailing VLAN (ie eth5.90 -> eth5). $title_clean = regsubst($title,'^(\w+)\.\d+$','\1') - $macaddy = getvar("::macaddress_${title_clean}") - } else { - $macaddy = $macaddress + $macaddy = $::networking['interfaces'][$title_clean]['mac'] } - # Validate booleans - validate_bool($userctl) - validate_bool($ipv6init) - validate_bool($ipv6autoconf) - validate_bool($peerdns) - validate_bool($ipv6peerdns) - validate_bool($manage_hwaddr) - validate_bool($flush) - validate_bool($arpcheck) network_if_base { $title: ensure => $ensure, diff --git a/manifests/init.pp b/manifests/init.pp index 6e3798f..e07b6d9 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -24,7 +24,7 @@ # class network { # Only run on RedHat derived systems. - case $::osfamily { + case $::os['family'] { 'RedHat': { } default: { fail('This network module only supports RedHat-based systems.') @@ -53,7 +53,7 @@ # $ensure - required - up|down # $ipaddress - optional # $netmask - optional -# $macaddress - required +# $macaddress - optional # $manage_hwaddr - optional - defaults to true # $gateway - optional # $noaliasrouting - optional - defaults to false @@ -105,59 +105,42 @@ # 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, - $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, + Enum['up', 'down'] $ensure, + Optional[Stdlib::MAC] $macaddress = undef, + Optional[IP::Address::V4::NoSubnet] $ipaddress = undef, + Optional[IP::Address::V4::NoSubnet] $netmask = undef, + Boolean $manage_hwaddr = true, + Optional[IP::Address::V4::NoSubnet] $gateway = undef, + Boolean $noaliasrouting = false, + Optional[IP::Address::V6] $ipv6address = undef, + Optional[IP::Address::V6::NoSubnet] $ipv6gateway = undef, + Boolean $ipv6init = false, + Boolean $ipv6autoconf = false, + Optional[Array[IP::Address::V6]] $ipv6secondaries = undef, + Network::If::Bootproto $bootproto = 'none', + Boolean $userctl = false, + Optional[String] $mtu = undef, + Optional[String] $dhcp_hostname = undef, + Optional[String] $ethtool_opts = undef, + Optional[String] $bonding_opts = undef, + Boolean $isalias = false, + Boolean $peerdns = false, + Boolean $ipv6peerdns = false, + Optional[IP::Address::NoSubnet] $dns1 = undef, + Optional[IP::Address::NoSubnet] $dns2 = undef, + Optional[String] $domain = undef, + Optional[String] $bridge = undef, + Optional[String] $linkdelay = undef, + Optional[String] $scope = undef, + Boolean $check_link_down = false, + Boolean $flush = false, + Optional[String] $defroute = undef, + Optional[String] $zone = undef, + Optional[String] $metric = undef, + Boolean $promisc = false, + Boolean $restart = true, + Boolean $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' @@ -183,14 +166,59 @@ 'down' => 'no', default => undef, } - $iftemplate = template('network/ifcfg-alias.erb') + $iftemplate = epp("${module_name}/ifcfg-alias.epp", { + interface => $interface, + bootproto => $bootproto, + onparent => $onparent, + ipaddress => $ipaddress, + netmask => $netmask, + gateway => $gateway, + ipv6address => $ipv6address, + noaliasrouting => $noaliasrouting, + userctl => $userctl, + zone => $zone, + metric => $metric, + }) } else { $onboot = $ensure ? { 'up' => 'yes', 'down' => 'no', default => undef, } - $iftemplate = template('network/ifcfg-eth.erb') + $iftemplate = epp("${module_name}/ifcfg-eth.epp", { + interface => $interface, + bootproto => $bootproto, + manage_hwaddr => $manage_hwaddr, + macaddress => $macaddress, + onboot => $onboot, + ipaddress => $ipaddress, + netmask => $netmask, + gateway => $gateway, + mtu => $mtu, + bonding_opts => $bonding_opts, + dhcp_hostname => $dhcp_hostname, + ethtool_opts => $ethtool_opts, + peerdns => $peerdns, + dns1 => $dns1_real, + dns2 => $dns2_real, + domain => $domain, + userctl => $userctl, + ipv6init => $ipv6init, + ipv6autoconf => $ipv6autoconf, + ipv6address => $ipv6address, + ipv6gateway => $ipv6gateway, + ipv6peerdns => $ipv6peerdns, + ipv6secondaries => $ipv6secondaries, + bridge => $bridge, + linkdelay => $linkdelay, + scope => $scope, + check_link_down => $check_link_down, + defroute => $defroute, + zone => $zone, + metric => $metric, + promisc => $promisc, + arpcheck => $arpcheck, + }) } if $flush { @@ -219,24 +247,3 @@ } } } # 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 diff --git a/manifests/route.pp b/manifests/route.pp index 27c7534..a803456 100644 --- a/manifests/route.pp +++ b/manifests/route.pp @@ -41,17 +41,11 @@ # Copyright (C) 2011 Mike Arnold, unless otherwise noted. # define network::route ( - $ipaddress, - $netmask, - $gateway, - $restart = true, + Array[IP::Address::V4::NoSubnet] $ipaddress, + Array[IP::Address::V4::NoSubnet] $netmask, + Array[IP::Address::V4::NoSubnet] $gateway, + Boolean $restart = true, ) { - # Validate our arrays - validate_array($ipaddress) - validate_array($netmask) - validate_array($gateway) - # Validate our booleans - validate_bool($restart) include '::network' @@ -63,7 +57,11 @@ owner => 'root', group => 'root', path => "/etc/sysconfig/network-scripts/route-${interface}", - content => template('network/route-eth.erb'), + content => epp("${module_name}/route-eth.epp", { + ipaddress => $ipaddress, + netmask => $netmask, + gateway => $gateway, + }), before => File["ifcfg-${interface}"], } diff --git a/metadata.json b/metadata.json index de0b60d..4f25415 100644 --- a/metadata.json +++ b/metadata.json @@ -11,7 +11,11 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">=2.3.0 <5.0.0" + "version_requirement": ">=4.24.0 <5.0.0" + }, + { + "name": "thrnio/ip", + "version_requirement": ">=1.0.0 < 2.0.0" } ], "operatingsystem_support": [ @@ -35,7 +39,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">=2.7.20 <5.0.0" + "version_requirement": ">=4.9.0 <5.0.0" } ] } diff --git a/spec/classes/network_global_spec.rb b/spec/classes/network_global_spec.rb index 5231852..9659ba3 100644 --- a/spec/classes/network_global_spec.rb +++ b/spec/classes/network_global_spec.rb @@ -6,7 +6,7 @@ context 'on a non-supported operatingsystem' do let :facts do { - :osfamily => 'foo', + :os => { :family => 'foo' } } end it 'should fail' do @@ -19,10 +19,14 @@ context 'on a supported operatingsystem, default parameters' do let(:params) {{}} let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '7.0', - :fqdn => 'localhost.localdomain', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '7', + } + }, + :networking => { :fqdn => 'localhost.localdomain' } } end it { should contain_class('network') } @@ -51,10 +55,14 @@ :restart => false }} let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '7.0', - :fqdn => 'localhost.localdomain', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '7', + } + }, + :networking => { :fqdn => 'localhost.localdomain' } } end it { should contain_class('network') } @@ -87,10 +95,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '7.0', - :fqdn => 'localhost.localdomain', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '7', + } + }, + :networking => { :fqdn => 'localhost.localdomain' } } end it 'should contain File[network.sysconfig] with correct contents' do @@ -119,10 +131,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :fqdn => 'localhost.localdomain', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { :fqdn => 'localhost.localdomain' } } end it 'should contain File[network.sysconfig] with correct contents' do @@ -134,7 +150,7 @@ end context 'on a supported operatingsystem, bad parameters' do - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} context 'gateway = foo' do let(:params) {{ :gateway => 'foo' }} @@ -213,10 +229,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :fqdn => 'localhost.localdomain', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { :fqdn => 'localhost.localdomain' } } end it 'should contain File[network.sysconfig] with correct contents' do diff --git a/spec/classes/network_init_spec.rb b/spec/classes/network_init_spec.rb index c44d416..2f44bf1 100644 --- a/spec/classes/network_init_spec.rb +++ b/spec/classes/network_init_spec.rb @@ -5,7 +5,7 @@ describe 'network', :type => 'class' do context 'on a non-supported operatingsystem' do - let(:facts) {{ :osfamily => 'foo' }} + let(:facts) {{ :os => { :family => 'foo' }}} it 'should fail' do expect { @@ -15,7 +15,7 @@ end context 'on a supported operatingsystem' do - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_service('network').with( :ensure => 'running', diff --git a/spec/defines/network_alias_range_spec.rb b/spec/defines/network_alias_range_spec.rb index 3abc951..4dcc2d1 100644 --- a/spec/defines/network_alias_range_spec.rb +++ b/spec/defines/network_alias_range_spec.rb @@ -14,7 +14,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /\$ensure must be either "up", "down", or "absent"./) + expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for Enum\['absent', 'down', 'up'\]/) end end @@ -28,7 +28,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /notAnIP is not an IP address./) + expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) end end @@ -42,7 +42,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /notAnIP is not an IP address./) + expect {should contain_file('ifcfg-bond77-range0')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) end end @@ -57,7 +57,7 @@ :clonenum_start => '3', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-eth99-range3').with( :ensure => 'present', :mode => '0644', @@ -91,7 +91,7 @@ :restart => false, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-eth99-range3').with( :ensure => 'present', :mode => '0644', @@ -124,7 +124,7 @@ :noaliasrouting => true, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-bond7-range9').with( :ensure => 'present', :mode => '0644', @@ -156,7 +156,7 @@ :clonenum_start => '9', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-bond6-range9').with( :ensure => 'absent', :path => '/etc/sysconfig/network-scripts/ifcfg-bond6-range9', @@ -179,7 +179,7 @@ :arpcheck => false, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-eth8-range9').with( :ensure => 'present', :mode => '0644', diff --git a/spec/defines/network_alias_spec.rb b/spec/defines/network_alias_spec.rb index b562460..1545df6 100644 --- a/spec/defines/network_alias_spec.rb +++ b/spec/defines/network_alias_spec.rb @@ -13,7 +13,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -26,7 +26,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /notAnIP is not an IP address./) + expect {should contain_file('ifcfg-eth1:1')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) end end @@ -38,7 +38,7 @@ :netmask => '255.255.255.0', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-bond2:1').with( :ensure => 'present', :mode => '0644', @@ -75,7 +75,7 @@ :zone => 'trusted', } end - let(:facts) {{ :osfamily => 'RedHat' }} + let(:facts) {{ :os => { :family => 'RedHat' }}} it { should contain_file('ifcfg-bond3:2').with( :ensure => 'present', :mode => '0644', diff --git a/spec/defines/network_bond_bridge_spec.rb b/spec/defines/network_bond_bridge_spec.rb index 272557d..e2732ba 100644 --- a/spec/defines/network_bond_bridge_spec.rb +++ b/spec/defines/network_bond_bridge_spec.rb @@ -12,7 +12,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -24,10 +24,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :macaddress_bond0 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { + :interfaces => { + :bond0 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-bond0').with( @@ -57,12 +67,16 @@ context 'on an older operatingsystem with /etc/modprobe.conf' do (['RedHat', 'CentOS', 'OEL', 'OracleLinux', 'SLC', 'Scientific']).each do |os| context "for operatingsystem #{os}" do - (['4.8', '5.9']).each do |osv| + (['4', '5']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -80,9 +94,13 @@ (['6', '9', '11']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -108,9 +126,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0' + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + } } end it { should contain_file('ifcfg-bond0').with( diff --git a/spec/defines/network_bond_dynamic_spec.rb b/spec/defines/network_bond_dynamic_spec.rb index 2b2d2f1..2872d33 100644 --- a/spec/defines/network_bond_dynamic_spec.rb +++ b/spec/defines/network_bond_dynamic_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1:1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-bond1:1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -22,10 +22,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :macaddress_bond2 => 'ff:aa:ff:aa:ff:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6' + } + }, + :networking => { + :interfaces => { + :bond2 => { + :mac => 'ff:aa:ff:aa:ff:aa' + } + } + } } end it { should contain_file('ifcfg-bond2').with( @@ -53,12 +63,16 @@ context 'on an older operatingsystem with /etc/modprobe.conf' do (['RedHat', 'CentOS', 'OEL', 'OracleLinux', 'SLC', 'Scientific']).each do |os| context "for operatingsystem #{os}" do - (['4.8', '5.9']).each do |osv| + (['4', '5']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond2').with( @@ -76,9 +90,13 @@ (['6', '9', '11']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond2').with( @@ -106,10 +124,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :macaddress_bond2 => 'ff:aa:ff:aa:ff:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { + :interfaces => { + :bond2 => { + :mac => 'ff:aa:ff:aa:ff:aa' + } + } + } } end it { should contain_file('ifcfg-bond2').with( diff --git a/spec/defines/network_bond_slave_spec.rb b/spec/defines/network_bond_slave_spec.rb index d8840da..d4535b0 100644 --- a/spec/defines/network_bond_slave_spec.rb +++ b/spec/defines/network_bond_slave_spec.rb @@ -12,7 +12,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth6')}.to raise_error(Puppet::Error, /123456 is not a MAC address./) + expect {should contain_file('ifcfg-eth6')}.to raise_error(Puppet::Error, /expects a match for Stdlib::MAC/) end end @@ -24,10 +24,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -61,8 +71,14 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { :family => 'RedHat' }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -100,10 +116,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :macaddress_eth3 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { + :interfaces => { + :eth3 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth3').with( diff --git a/spec/defines/network_bond_spec.rb b/spec/defines/network_bond_spec.rb index b28d4d4..c65285c 100644 --- a/spec/defines/network_bond_spec.rb +++ b/spec/defines/network_bond_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -22,10 +22,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :macaddress_bond0 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { + :interfaces => { + :bond0 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-bond0').with( @@ -53,12 +63,16 @@ context 'on an older operatingsystem with /etc/modprobe.conf' do (['RedHat', 'CentOS', 'OEL', 'OracleLinux', 'SLC', 'Scientific']).each do |os| context "for operatingsystem #{os}" do - (['4.8', '5.9']).each do |osv| + (['4', '5']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -76,9 +90,13 @@ (['6', '9', '11']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -104,9 +122,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0' + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + } } end it { should contain_file('ifcfg-bond0').with( diff --git a/spec/defines/network_bond_static_spec.rb b/spec/defines/network_bond_static_spec.rb index 90f14ef..8371d4e 100644 --- a/spec/defines/network_bond_static_spec.rb +++ b/spec/defines/network_bond_static_spec.rb @@ -13,7 +13,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -26,7 +26,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /notAnIP is not an IP address./) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) end end @@ -40,7 +40,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /notAnIP is not an IPv6 address./) + expect {should contain_file('ifcfg-bond1')}.to raise_error(Puppet::Error, /(expects an IP::Address::V6 |expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) end end @@ -53,10 +53,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :macaddress_bond0 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { + :interfaces => { + :bond0 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-bond0').with( @@ -87,12 +97,16 @@ context 'on an older operatingsystem with /etc/modprobe.conf' do (['RedHat', 'CentOS', 'OEL', 'OracleLinux', 'SLC', 'Scientific']).each do |os| context "for operatingsystem #{os}" do - (['4.8', '5.9']).each do |osv| + (['4', '5']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -110,9 +124,13 @@ (['6', '9', '11']).each do |osv| context "for operatingsystemrelease #{osv}" do let :facts do { - :osfamily => 'RedHat', - :operatingsystem => os, - :operatingsystemrelease => osv, + :os => { + :family => 'RedHat', + :name => os, + :release => { + :major => osv + } + } } end it { should contain_augeas('modprobe.conf_bond0').with( @@ -152,9 +170,13 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0' + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + } } end it { should contain_file('ifcfg-bond0').with( diff --git a/spec/defines/network_bridge_dynamic_spec.rb b/spec/defines/network_bridge_dynamic_spec.rb index 77eeec3..8466411 100644 --- a/spec/defines/network_bridge_dynamic_spec.rb +++ b/spec/defines/network_bridge_dynamic_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -23,7 +23,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /"notABool" is not a boolean./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a Boolean/) end end @@ -34,7 +34,13 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + } } end it { should contain_file('ifcfg-br1').with( @@ -70,7 +76,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( @@ -109,7 +117,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( diff --git a/spec/defines/network_bridge_spec.rb b/spec/defines/network_bridge_spec.rb index 787be1b..cd90d6e 100644 --- a/spec/defines/network_bridge_spec.rb +++ b/spec/defines/network_bridge_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -23,7 +23,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /"notABool" is not a boolean./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a Boolean value/) end end @@ -34,7 +34,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( @@ -70,7 +72,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( @@ -108,7 +112,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( diff --git a/spec/defines/network_bridge_static_spec.rb b/spec/defines/network_bridge_static_spec.rb index a8dde12..d55f073 100644 --- a/spec/defines/network_bridge_static_spec.rb +++ b/spec/defines/network_bridge_static_spec.rb @@ -13,7 +13,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -26,7 +26,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /notAnIP is not an IP address./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet /) end end @@ -40,7 +40,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /notAnIP is not an IPv6 address./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /(expects an IP::Address::V6 |expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) end end @@ -54,7 +54,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /"notABool" is not a boolean./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a Boolean/) end end @@ -68,7 +68,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /"notABool" is not a boolean./) + expect {should contain_file('ifcfg-br77')}.to raise_error(Puppet::Error, /expects a Boolean/) end end @@ -81,7 +81,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( @@ -119,7 +121,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( @@ -169,7 +173,9 @@ } end let :facts do { - :osfamily => 'RedHat', + :os => { + :family => 'RedHat' + } } end it { should contain_file('ifcfg-br1').with( diff --git a/spec/defines/network_if_bridge_spec.rb b/spec/defines/network_if_bridge_spec.rb index 1eaa6cb..ec24ef4 100644 --- a/spec/defines/network_if_bridge_spec.rb +++ b/spec/defines/network_if_bridge_spec.rb @@ -12,7 +12,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -24,8 +24,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -62,8 +70,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( diff --git a/spec/defines/network_if_dynamic_spec.rb b/spec/defines/network_if_dynamic_spec.rb index 7ff2336..599be0a 100644 --- a/spec/defines/network_if_dynamic_spec.rb +++ b/spec/defines/network_if_dynamic_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -22,8 +22,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth99 => 'ff:aa:ff:aa:ff:aa', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth99 => { + :mac => 'ff:aa:ff:aa:ff:aa' + } + } + } } end it { should contain_file('ifcfg-eth99').with( @@ -67,8 +75,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth99 => 'ff:aa:ff:aa:ff:aa', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth99 => { + :mac => 'ff:aa:ff:aa:ff:aa' + } + } + } } end it { should contain_file('ifcfg-eth99').with( @@ -105,8 +121,16 @@ let(:title) { 'eth45.302' } let(:params) {{ :ensure => 'up' }} let :facts do { - :osfamily => 'RedHat', - :macaddress_eth45 => 'bb:cc:bb:cc:bb:cc', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth45 => { + :mac => 'bb:cc:bb:cc:bb:cc' + } + } + } } end it { should contain_file('ifcfg-eth45.302').with( @@ -139,8 +163,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth0 => 'bb:cc:bb:cc:bb:cc', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth0 => { + :mac => 'bb:cc:bb:cc:bb:cc' + } + } + } } end it { should contain_file('ifcfg-eth0').with( diff --git a/spec/defines/network_if_promisc_spec.rb b/spec/defines/network_if_promisc_spec.rb index c4e32f5..adac4dd 100644 --- a/spec/defines/network_if_promisc_spec.rb +++ b/spec/defines/network_if_promisc_spec.rb @@ -11,11 +11,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :operatingsystemmajrelease => '6', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -68,11 +77,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :operatingsystemmajrelease => '6', - :macaddress_eth3 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { + :interfaces => { + :eth3 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth3').with( diff --git a/spec/defines/network_if_spec.rb b/spec/defines/network_if_spec.rb index ea20ced..2a77da8 100644 --- a/spec/defines/network_if_spec.rb +++ b/spec/defines/network_if_spec.rb @@ -11,7 +11,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth1')}.to raise_error(Puppet::Error, /\$ensure must be either "up" or "down"./) + expect {should contain_file('ifcfg-eth1')}.to raise_error(Puppet::Error, /expects a match for Enum\['down', 'up'\]/) end end @@ -22,10 +22,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :macaddress_eth0 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { + :interfaces => { + :eth0 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth0').with( @@ -59,10 +69,20 @@ } end let :facts do { - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :macaddress_eth0 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat', + :name => 'RedHat', + :release => { + :major => '6', + } + }, + :networking => { + :interfaces => { + :eth0 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth0').with( diff --git a/spec/defines/network_if_static_spec.rb b/spec/defines/network_if_static_spec.rb index 4409578..4f4058c 100644 --- a/spec/defines/network_if_static_spec.rb +++ b/spec/defines/network_if_static_spec.rb @@ -13,7 +13,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /notAnIP is not an IP address\./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /expects a match for IP::Address::V4::NoSubnet/) end end @@ -27,7 +27,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /notAnIP is not an IPv6 address\./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects a value of type Undef, IP::Address::V6|expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) end end @@ -41,9 +41,7 @@ } end it 'should fail' do - # there are major differences in the way that different ruby versions translate a hash into a string - # which makes it hard to match the whole string - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /.*notAn.*IP.* is not an IPv6 address\./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects a value of type Undef, IP::Address::V6|expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) end end @@ -61,7 +59,7 @@ } end it 'should fail' do - expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /notAnIP is not an IP\(v6\) address\./) + expect {should contain_file('ifcfg-eth77')}.to raise_error(Puppet::Error, /(expects an IP::Address::V6 |expects a match for Variant\[IP::Address::V6::Full .*, IP::Address::V6::Compressed)/) end end @@ -74,8 +72,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -114,8 +120,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -172,8 +186,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -228,8 +250,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth6 => 'bb:cc:bb:cc:bb:cc', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth6 => { + :mac => 'bb:cc:bb:cc:bb:cc' + } + } + } } end it { should contain_file('ifcfg-eth6.203').with( @@ -266,8 +296,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth0 => 'bb:cc:bb:cc:bb:cc', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth0 => { + :mac => 'bb:cc:bb:cc:bb:cc' + } + } + } } end it { should contain_file('ifcfg-eth0').with( @@ -303,8 +341,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_exec('network-flush').with_command('ip addr flush dev eth1').that_comes_before('Service[network]') } @@ -323,8 +369,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( @@ -369,8 +423,16 @@ } end let :facts do { - :osfamily => 'RedHat', - :macaddress_eth1 => 'fe:fe:fe:aa:aa:aa', + :os => { + :family => 'RedHat' + }, + :networking => { + :interfaces => { + :eth1 => { + :mac => 'fe:fe:fe:aa:aa:aa' + } + } + } } end it { should contain_file('ifcfg-eth1').with( diff --git a/spec/defines/network_route_spec.rb b/spec/defines/network_route_spec.rb index 8908418..36e5c31 100644 --- a/spec/defines/network_route_spec.rb +++ b/spec/defines/network_route_spec.rb @@ -13,7 +13,12 @@ :gateway => [ '192.168.1.2', ], } end - let(:facts) {{ :osfamily => 'RedHat' }} + let :facts do { + :os => { + :family => 'RedHat' + } + } + end it { should contain_file('route-eth1').with( :ensure => 'present', :mode => '0644', @@ -42,7 +47,12 @@ :restart => false, } end - let(:facts) {{ :osfamily => 'RedHat' }} + let :facts do { + :os => { + :family => 'RedHat' + } + } + end it { should contain_file('route-eth1').with( :ensure => 'present', :mode => '0644', @@ -70,7 +80,12 @@ :gateway => [ '192.168.1.1', '10.0.0.1', ] } end - let(:facts) {{ :osfamily => 'RedHat' }} + let :facts do { + :os => { + :family => 'RedHat' + } + } + end it { should contain_file('route-eth2').with( :ensure => 'present', :mode => '0644', diff --git a/templates/ifcfg-alias-range.epp b/templates/ifcfg-alias-range.epp new file mode 100644 index 0000000..2ceee0f --- /dev/null +++ b/templates/ifcfg-alias-range.epp @@ -0,0 +1,12 @@ +### +### File managed by Puppet +### +IPADDR_START=<%= $ipaddress_start %> +IPADDR_END=<%= $ipaddress_end %> +CLONENUM_START=<%= $clonenum_start %> +NO_ALIASROUTING=<%= bool2str($noaliasrouting, 'yes', 'no') %> +<% if $netmask { %>NETMASK=<%= $netmask %><% } %> +<% if $broadcast { %>BROADCAST=<%= $broadcast %><% } %> +<% if !$arpcheck { %>ARPCHECK=no<% } %> +ONPARENT=<%= $onparent %> +NM_CONTROLLED=no diff --git a/templates/ifcfg-alias-range.erb b/templates/ifcfg-alias-range.erb deleted file mode 100644 index 018f55e..0000000 --- a/templates/ifcfg-alias-range.erb +++ /dev/null @@ -1,17 +0,0 @@ -### -### File managed by Puppet -### -IPADDR_START=<%= @ipaddress_start %> -IPADDR_END=<%= @ipaddress_end %> -CLONENUM_START=<%= @clonenum_start %> -<% if !@noaliasrouting %>NO_ALIASROUTING=no -<% else %>NO_ALIASROUTING=yes -<% end -%> -<% if @netmask %>NETMASK=<%= @netmask %> -<% end -%> -<% if @broadcast %>BROADCAST=<%= @broadcast %> -<% end -%> -<% if !@arpcheck %>ARPCHECK=no -<% end -%> -ONPARENT=<%= @onparent %> -NM_CONTROLLED=no diff --git a/templates/ifcfg-alias.epp b/templates/ifcfg-alias.epp new file mode 100644 index 0000000..0f23995 --- /dev/null +++ b/templates/ifcfg-alias.epp @@ -0,0 +1,16 @@ +### +### File managed by Puppet +### +DEVICE=<%= $interface %> +BOOTPROTO=<%= $bootproto %> +ONPARENT=<%= $onparent %> +TYPE=Ethernet +<% if $ipaddress { %>IPADDR=<%= $ipaddress %><% } %> +<% if $netmask { %>NETMASK=<%= $netmask %><% } %> +<% if $gateway { %>GATEWAY=<%= $gateway %><% } %> +<% if $ipv6address { %>IPV6ADDR=<%= $ipv6address %><% } %> +NO_ALIASROUTING=<%= bool2str($noaliasrouting, 'yes', 'no') %> +<% if $userctl { %>USERCTL=yes<% } %> +<% if $zone { %>ZONE=<%= $zone %><% } %> +<% if $metric { %>METRIC=<%= $metric %><% } %> +NM_CONTROLLED=no diff --git a/templates/ifcfg-alias.erb b/templates/ifcfg-alias.erb deleted file mode 100644 index 3961edb..0000000 --- a/templates/ifcfg-alias.erb +++ /dev/null @@ -1,25 +0,0 @@ -### -### File managed by Puppet -### -DEVICE=<%= @interface %> -BOOTPROTO=<%= @bootproto %> -ONPARENT=<%= @onparent %> -TYPE=Ethernet -<% if @ipaddress %>IPADDR=<%= @ipaddress %> -<% end -%> -<% if @netmask %>NETMASK=<%= @netmask %> -<% end -%> -<% if @gateway %>GATEWAY=<%= @gateway %> -<% end -%> -<% if @ipv6address %>IPV6ADDR=<%= @ipv6address %> -<% end -%> -<% if !@noaliasrouting %>NO_ALIASROUTING=no -<% else %>NO_ALIASROUTING=yes -<% end -%> -<% if @userctl %>USERCTL=yes -<% end -%> -<% if @zone %>ZONE=<%= @zone %> -<% end -%> -<% if @metric %>METRIC=<%= @metric %> -<% end -%> -NM_CONTROLLED=no diff --git a/templates/ifcfg-bond.epp b/templates/ifcfg-bond.epp new file mode 100644 index 0000000..0305543 --- /dev/null +++ b/templates/ifcfg-bond.epp @@ -0,0 +1,16 @@ +### +### File managed by Puppet +### +DEVICE=<%= $interface %> +<% if $macaddress { %>HWADDR=<%= $macaddress %><% } %> +MASTER=<%= $master %> +SLAVE=yes +TYPE=Ethernet +<% if $ethtool_opts { %>ETHTOOL_OPTS="<%= $ethtool_opts %>"<% } %> +<% if $defroute { %>DEFROUTE=<%= $defroute %><% } %> +<% if $zone { %>ZONE=<%= $zone %><% } %> +<% if $metric { %>METRIC=<%= $metric %><% } %> +<% if $bootproto { %>BOOTPROTO=<%= $bootproto %><% } %> +<% if $onboot { %>ONBOOT=<%= $onboot %><% } %> +<% if $userctl { %>USERCTL=yes<% } %> +NM_CONTROLLED=no diff --git a/templates/ifcfg-bond.erb b/templates/ifcfg-bond.erb deleted file mode 100644 index 3055d47..0000000 --- a/templates/ifcfg-bond.erb +++ /dev/null @@ -1,24 +0,0 @@ -### -### File managed by Puppet -### -DEVICE=<%= @interface %> -<% if @macaddress and @macaddress != '' %>HWADDR=<%= @macaddress %> -<% end -%> -MASTER=<%= @master %> -SLAVE=yes -TYPE=Ethernet -<% if @ethtool_opts %>ETHTOOL_OPTS="<%= @ethtool_opts %>" -<% end -%> -<% if @defroute %>DEFROUTE=<%= @defroute %> -<% end -%> -<% if @zone %>ZONE=<%= @zone %> -<% end -%> -<% if @metric %>METRIC=<%= @metric %> -<% end -%> -<% if @bootproto %>BOOTPROTO=<%= @bootproto %> -<% end -%> -<% if @onboot %>ONBOOT=<%= @onboot %> -<% end -%> -<% if @userctl %>USERCTL=yes -<% end -%> -NM_CONTROLLED=no diff --git a/templates/ifcfg-br.epp b/templates/ifcfg-br.epp new file mode 100644 index 0000000..c6a0d38 --- /dev/null +++ b/templates/ifcfg-br.epp @@ -0,0 +1,26 @@ +### +### File managed by Puppet +### +DEVICE=<%= $interface %> +BOOTPROTO=<%= $bootproto %> +ONBOOT=<%= $onboot %> +TYPE=Bridge +<% if $ipaddress { %>IPADDR=<%= $ipaddress %><% } %> +<% if $netmask { %>NETMASK=<%= $netmask %><% } %> +<% if $gateway { %>GATEWAY=<%= $gateway %><% } %> +<%- if $ipv6init { -%> +IPV6INIT=yes +<% if $ipv6address { %>IPV6ADDR=<%= $ipv6address %><% } %> +<% if $ipv6gateway { %>IPV6_DEFAULTGW=<%= $ipv6gateway %><% } %> +<% if $ipv6peerdns { %>IPV6_PEERDNS=yes<% } %> +<%- } -%> +PEERDNS=<%= bool2str($peerdns, 'yes', 'no') %> +<% if $dns1 { %>DNS1=<%= $dns1 %><% } %> +<% if $dns2 { %>DNS2=<%= $dns2 %><% } %> +<% if $domain { %>DOMAIN="<%= $domain %>"<% } %> +<% if $userctl { %>USERCTL=yes<% } %> +DELAY=<%= $delay %> +STP=<%= bool2str($stp, 'yes', 'no') %> +<% if $bridging_opts { %>BRIDGING_OPTS="<%= $bridging_opts %>"<% } %> +<% if $scope { %>SCOPE="<%= $scope %>"<% } %> +NM_CONTROLLED=no diff --git a/templates/ifcfg-br.erb b/templates/ifcfg-br.erb deleted file mode 100644 index dfba2d6..0000000 --- a/templates/ifcfg-br.erb +++ /dev/null @@ -1,41 +0,0 @@ -### -### File managed by Puppet -### -DEVICE=<%= @interface %> -BOOTPROTO=<%= @bootproto %> -ONBOOT=<%= @onboot %> -TYPE=Bridge -<% if @ipaddress %>IPADDR=<%= @ipaddress %> -<% end -%> -<% if @netmask %>NETMASK=<%= @netmask %> -<% end -%> -<% if @gateway %>GATEWAY=<%= @gateway %> -<% end -%> -<% if @ipv6init %>IPV6INIT=yes -<% if @ipv6address %>IPV6ADDR=<%= @ipv6address %> -<% end -%> -<% if @ipv6gateway %>IPV6_DEFAULTGW=<%= @ipv6gateway %> -<% end -%> -<% if @ipv6peerdns %>IPV6_PEERDNS=yes -<% end -%> -<% end -%> -<% if !@peerdns %>PEERDNS=no -<% else %>PEERDNS=yes -<% end -%> -<% if @dns1_real %>DNS1=<%= @dns1_real %> -<% end -%> -<% if @dns2_real %>DNS2=<%= @dns2_real %> -<% end -%> -<% if @domain %>DOMAIN="<%= @domain %>" -<% end -%> -<% if @userctl %>USERCTL=yes -<% end -%> -DELAY=<%= @delay %> -<% if !@stp %>STP=no -<% else %>STP=yes -<% end -%> -<% if @bridging_opts %>BRIDGING_OPTS="<%= @bridging_opts %>" -<% end -%> -<% if @scope %>SCOPE="<%= @scope %>" -<% end -%> -NM_CONTROLLED=no diff --git a/templates/ifcfg-eth.epp b/templates/ifcfg-eth.epp new file mode 100644 index 0000000..08d1af2 --- /dev/null +++ b/templates/ifcfg-eth.epp @@ -0,0 +1,45 @@ +### +### File managed by Puppet +### +DEVICE=<%= $interface %> +BOOTPROTO=<%= $bootproto %> +<% if $manage_hwaddr and $macaddress { %>HWADDR=<%= $macaddress %><% } %> +ONBOOT=<%= $onboot %> +HOTPLUG=<%= $onboot %> +TYPE=Ethernet +<% if $ipaddress { %>IPADDR=<%= $ipaddress %><% } %> +<% if $netmask { %>NETMASK=<%= $netmask %><% } %> +<% if $gateway { %>GATEWAY=<%= $gateway %><% } %> +<% if $mtu { %>MTU=<%= $mtu %><% } %> +<% if $bonding_opts { %>BONDING_OPTS="<%= $bonding_opts %>"<% } %> +<% if $dhcp_hostname { %>DHCP_HOSTNAME="<%= $dhcp_hostname %>"<% } %> +<% if $ethtool_opts { %>ETHTOOL_OPTS="<%= $ethtool_opts %>"<% } %> +PEERDNS=<%= bool2str($peerdns, 'yes', 'no') %> +<% if $dns1 { %>DNS1=<%= $dns1 %><% } %> +<% if $dns2 { %>DNS2=<%= $dns2 %><% } %> +<% if $domain { %>DOMAIN="<%= $domain %>"<% } %> +<% if $userctl { %>USERCTL=yes<% } %> +<%- if $ipv6init { -%> +IPV6INIT=yes +IPV6_AUTOCONF=<%= bool2str($ipv6autoconf, 'yes', 'no') %> +<% if $ipv6address { %>IPV6ADDR=<%= $ipv6address %><% } %> +<% if $ipv6gateway { %>IPV6_DEFAULTGW=<%= $ipv6gateway %><% } %> +IPV6_PEERDNS=<%= bool2str($ipv6peerdns, 'yes', 'no') %> +<%- if $ipv6secondaries { -%> +IPV6ADDR_SECONDARIES="<%= join($ipv6secondaries, ' ') %>" +<%- } -%> +<%- } -%> +<% if $bridge { %>BRIDGE=<%= $bridge %><% } %> +<% if $linkdelay { %>LINKDELAY=<%= $linkdelay %><% } %> +<% if $scope { %>SCOPE="<%= $scope %>"<% } %> +<% if $check_link_down { %> +check_link_down() { + return 1; +} +<% } -%> +<% if $defroute { %>DEFROUTE=<%= $defroute %><% } %> +<% if $zone { %>ZONE=<%= $zone %><% } %> +<% if $metric { %>METRIC=<%= $metric %><% } %> +<% if $promisc { %>PROMISC=yes<% } %> +<% if !$arpcheck { %>ARPCHECK=no<% } %> +NM_CONTROLLED=no diff --git a/templates/ifcfg-eth.erb b/templates/ifcfg-eth.erb deleted file mode 100644 index 2f1addb..0000000 --- a/templates/ifcfg-eth.erb +++ /dev/null @@ -1,73 +0,0 @@ -### -### File managed by Puppet -### -DEVICE=<%= @interface %> -BOOTPROTO=<%= @bootproto %> -<% if @manage_hwaddr and @macaddress and @macaddress != '' -%> -HWADDR=<%= @macaddress %> -<% end -%> -ONBOOT=<%= @onboot %> -HOTPLUG=<%= @onboot %> -TYPE=Ethernet -<% if @ipaddress and @ipaddress != '' %>IPADDR=<%= @ipaddress %> -<% end -%> -<% if @netmask and @netmask != '' %>NETMASK=<%= @netmask %> -<% end -%> -<% if @gateway and @gateway != '' %>GATEWAY=<%= @gateway %> -<% end -%> -<% if @mtu %>MTU=<%= @mtu %> -<% end -%> -<% if @bonding_opts %>BONDING_OPTS="<%= @bonding_opts %>" -<% end -%> -<% if @dhcp_hostname %>DHCP_HOSTNAME="<%= @dhcp_hostname %>" -<% end -%> -<% if @ethtool_opts %>ETHTOOL_OPTS="<%= @ethtool_opts %>" -<% end -%> -<% if !@peerdns %>PEERDNS=no -<% else %>PEERDNS=yes -<% end -%> -<% if @dns1_real %>DNS1=<%= @dns1_real %> -<% end -%> -<% if @dns2_real %>DNS2=<%= @dns2_real %> -<% end -%> -<% if @domain %>DOMAIN="<%= @domain %>" -<% end -%> -<% if @userctl %>USERCTL=yes -<% end -%> -<% if @ipv6init %> -IPV6INIT=yes -<% if !@ipv6autoconf %>IPV6_AUTOCONF=no -<% else %>IPV6_AUTOCONF=yes -<% end -%> -<% if @ipv6address %>IPV6ADDR=<%= @ipv6address %> -<% end -%> -<% if @ipv6gateway %>IPV6_DEFAULTGW=<%= @ipv6gateway %> -<% end -%> -<% if !@ipv6peerdns %>IPV6_PEERDNS=no -<% else %>IPV6_PEERDNS=yes -<% end -%> -<% if @ipv6secondaries and @ipv6secondaries.length > 0 %>IPV6ADDR_SECONDARIES="<%= @ipv6secondaries.join(' ') %>" -<% end -%> -<% end -%> -<% if @bridge %>BRIDGE=<%= @bridge %> -<% end -%> -<% if @linkdelay %>LINKDELAY=<%= @linkdelay %> -<% end -%> -<% if @scope %>SCOPE="<%= @scope %>" -<% end -%> -<% if @check_link_down %> -check_link_down() { - return 1; -} -<% end -%> -<% if @defroute %>DEFROUTE=<%= @defroute %> -<% end -%> -<% if @zone %>ZONE=<%= @zone %> -<% end -%> -<% if @metric %>METRIC=<%= @metric %> -<% end -%> -<% if @promisc %>PROMISC=yes -<% end -%> -<% if !@arpcheck %>ARPCHECK=no -<% end -%> -NM_CONTROLLED=no diff --git a/templates/network.epp b/templates/network.epp new file mode 100644 index 0000000..e7f7b3c --- /dev/null +++ b/templates/network.epp @@ -0,0 +1,16 @@ +### +### File managed by Puppet +### +NETWORKING=yes +NETWORKING_IPV6=<%= bool2str($ipv6networking, 'yes', 'no') %> +<%- if $ipv6networking { -%> +<% if $ipv6gateway { %>IPV6_DEFAULTGW=<%= $ipv6gateway %><% } %> +<% if $ipv6defaultdev { %>IPV6_DEFAULTDEV=<%= $ipv6defaultdev %><% } %> +<% } -%> +HOSTNAME=<%= $hostname %> +<% if $gateway { %>GATEWAY=<%= $gateway %><% } %> +<% if $gatewaydev { %>GATEWAYDEV=<%= $gatewaydev %><% } %> +<% if $nisdomain { %>NISDOMAIN=<%= $nisdomain %><% } %> +<% if $vlan { %>VLAN=<%= $vlan %><% } %> +<% if $nozeroconf { %>NOZEROCONF=<%= $nozeroconf %><% } %> +<% if $requestreopen { %>RES_OPTIONS="single-request-reopen"<% } %> diff --git a/templates/network.erb b/templates/network.erb deleted file mode 100644 index d3ce54a..0000000 --- a/templates/network.erb +++ /dev/null @@ -1,26 +0,0 @@ -### -### File managed by Puppet -### -NETWORKING=yes -<% if !@ipv6networking %>NETWORKING_IPV6=no -<% else %>NETWORKING_IPV6=yes -<% if @ipv6gateway %>IPV6_DEFAULTGW=<%= @ipv6gateway %> -<% end -%> -<% if @ipv6defaultdev %>IPV6_DEFAULTDEV=<%= @ipv6defaultdev %> -<% end -%> -<% end -%> -<% if @hostname %>HOSTNAME=<%= @hostname %> -<% else %>HOSTNAME=<%= scope.lookupvar('::fqdn') %> -<% end -%> -<% if @gateway %>GATEWAY=<%= @gateway %> -<% end -%> -<% if @gatewaydev %>GATEWAYDEV=<%= @gatewaydev %> -<% end -%> -<% if @nisdomain %>NISDOMAIN=<%= @nisdomain %> -<% end -%> -<% if @vlan %>VLAN=<%= @vlan %> -<% end -%> -<% if @nozeroconf %>NOZEROCONF=<%= @nozeroconf %> -<% end -%> -<% if @requestreopen %>RES_OPTIONS="single-request-reopen" -<% end -%> diff --git a/templates/route-eth.epp b/templates/route-eth.epp new file mode 100644 index 0000000..af0da8a --- /dev/null +++ b/templates/route-eth.epp @@ -0,0 +1,12 @@ +### +### File managed by Puppet +### +<% $ipaddress.each |$index, $item| { -%> +ADDRESS<%= $index %>=<%= $item %> +<% } -%> +<% $netmask.each |$index, $item| { -%> +NETMASK<%= $index %>=<%= $item %> +<% } -%> +<% $gateway.each |$index, $item| { -%> +GATEWAY<%= $index %>=<%= $item %> +<% } -%> diff --git a/templates/route-eth.erb b/templates/route-eth.erb deleted file mode 100644 index 237df75..0000000 --- a/templates/route-eth.erb +++ /dev/null @@ -1,12 +0,0 @@ -### -### File managed by Puppet -### -<% num = 0; @ipaddress.each do |addr| -%> -ADDRESS<%= num %>=<%= addr %> -<% num += 1; end -%> -<% num = 0; @netmask.each do |mask| -%> -NETMASK<%= num %>=<%= mask %> -<% num += 1; end -%> -<% num = 0; @gateway.each do |gw| -%> -GATEWAY<%= num %>=<%= gw %> -<% num += 1; end -%> diff --git a/tests/bond-static.pp b/tests/bond-static.pp index de05235..24974b0 100644 --- a/tests/bond-static.pp +++ b/tests/bond-static.pp @@ -27,14 +27,14 @@ # bonded slave interface - static network::bond::slave { 'eth1': - macaddress => $::macaddress_eth1, + macaddress => $::networking['interfaces']['eth1']['mac'], ethtool_opts => 'speed 1000 duplex full autoneg off', master => 'bond0', } # bonded slave interface - static network::bond::slave { 'eth3': - macaddress => $::macaddress_eth3, + macaddress => $::networking['interfaces']['eth3']['mac'], ethtool_opts => 'speed 100 duplex half autoneg off', master => 'bond0', } diff --git a/tests/route.pp b/tests/route.pp index 5b95026..af96373 100644 --- a/tests/route.pp +++ b/tests/route.pp @@ -9,5 +9,5 @@ network::if::dynamic { 'eth2': ensure => 'down', - macaddress => $::macaddress_eth2, + macaddress => $::networking['interfaces']['eth2']['mac'], } diff --git a/types/if/bootproto.pp b/types/if/bootproto.pp new file mode 100644 index 0000000..3350d23 --- /dev/null +++ b/types/if/bootproto.pp @@ -0,0 +1,8 @@ +# Acceptable values for BOOTPROTO +# +# Only "dhcp" and "bootp" are used in /etc/sysconfig/network-scripts +# +# "static" and "none" are used in some parts of the module, +# and those values have no side effects, so we accept them too. +# +type Network::If::Bootproto = Enum['none', 'static', 'dhcp', 'bootp']