diff --git a/README.md b/README.md index 3d167aa..6e14597 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,13 @@ Normal interface - dhcp: ethtool_opts => 'autoneg off speed 100 duplex full', } +Normal interface - dhcp (persistent dhclient): + + network::if::dynamic { 'eth2': + ensure => 'up', + persistent_dhclient => true, + } + Normal interface - bootp (minimal): network::if::dynamic { 'eth2': diff --git a/manifests/if/dynamic.pp b/manifests/if/dynamic.pp index 1bc4b16..2e7fa49 100644 --- a/manifests/if/dynamic.pp +++ b/manifests/if/dynamic.pp @@ -47,20 +47,21 @@ # 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, + $macaddress = undef, + $manage_hwaddr = true, + $bootproto = 'dhcp', + $userctl = false, + $mtu = undef, + $dhcp_hostname = undef, + $persistent_dhclient = false, + $ethtool_opts = undef, + $peerdns = false, + $linkdelay = undef, + $check_link_down = false, + $defroute = undef, + $zone = undef, + $metric = undef, + $restart = true, ) { # Validate our regular expressions $states = [ '^up$', '^down$' ] @@ -77,25 +78,27 @@ validate_bool($userctl) validate_bool($peerdns) validate_bool($manage_hwaddr) + validate_bool($persistent_dhclient) network_if_base { $title: - ensure => $ensure, - ipaddress => '', - netmask => '', - gateway => '', - macaddress => $macaddy, - manage_hwaddr => $manage_hwaddr, - bootproto => $bootproto, - userctl => $userctl, - mtu => $mtu, - dhcp_hostname => $dhcp_hostname, - ethtool_opts => $ethtool_opts, - peerdns => $peerdns, - linkdelay => $linkdelay, - check_link_down => $check_link_down, - defroute => $defroute, - zone => $zone, - metric => $metric, - restart => $restart, + ensure => $ensure, + ipaddress => '', + netmask => '', + gateway => '', + macaddress => $macaddy, + manage_hwaddr => $manage_hwaddr, + bootproto => $bootproto, + userctl => $userctl, + mtu => $mtu, + dhcp_hostname => $dhcp_hostname, + persistent_dhclient => $persistent_dhclient, + ethtool_opts => $ethtool_opts, + peerdns => $peerdns, + linkdelay => $linkdelay, + check_link_down => $check_link_down, + defroute => $defroute, + zone => $zone, + metric => $metric, + restart => $restart, } } # define network::if::dynamic diff --git a/manifests/init.pp b/manifests/init.pp index 6e3798f..5d55552 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -50,35 +50,36 @@ # # === Parameters: # -# $ensure - required - up|down -# $ipaddress - optional -# $netmask - optional -# $macaddress - required -# $manage_hwaddr - optional - defaults to true -# $gateway - optional -# $noaliasrouting - optional - defaults to false -# $bootproto - optional -# $userctl - optional - defaults to false -# $mtu - optional -# $dhcp_hostname - optional -# $ethtool_opts - optional -# $bonding_opts - optional -# $isalias - optional -# $peerdns - optional -# $dns1 - optional -# $dns2 - optional -# $domain - optional -# $bridge - optional -# $scope - optional -# $linkdelay - optional -# $check_link_down - optional -# $flush - optional -# $zone - optional -# $metric - optional -# $defroute - optional -# $promisc - optional - defaults to false -# $restart - optional - defaults to true -# $arpcheck - optional - defaults to true +# $ensure - required - up|down +# $ipaddress - optional +# $netmask - optional +# $macaddress - required +# $manage_hwaddr - optional - defaults to true +# $gateway - optional +# $noaliasrouting - optional - defaults to false +# $bootproto - optional +# $userctl - optional - defaults to false +# $mtu - optional +# $dhcp_hostname - optional +# $persistent_dhclient - optional - defaults to false +# $ethtool_opts - optional +# $bonding_opts - optional +# $isalias - optional +# $peerdns - optional +# $dns1 - optional +# $dns2 - optional +# $domain - optional +# $bridge - optional +# $scope - optional +# $linkdelay - optional +# $check_link_down - optional +# $flush - optional +# $zone - optional +# $metric - optional +# $defroute - optional +# $promisc - optional - defaults to false +# $restart - optional - defaults to true +# $arpcheck - optional - defaults to true # # === Actions: # @@ -91,7 +92,6 @@ # SCOPE= # SRCADDR= # NOZEROCONF=yes -# PERSISTENT_DHCLIENT=yes|no|1|0 # DHCPRELEASE=yes|no|1|0 # DHCLIENT_IGNORE_GATEWAY=yes|no|1|0 # REORDER_HDR=yes|no @@ -107,39 +107,40 @@ 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, + $ipaddress = undef, + $netmask = undef, + $manage_hwaddr = true, + $gateway = undef, + $noaliasrouting = false, + $ipv6address = undef, + $ipv6gateway = undef, + $ipv6init = false, + $ipv6autoconf = false, + $ipv6secondaries = undef, + $bootproto = 'none', + $userctl = false, + $mtu = undef, + $dhcp_hostname = undef, + $persistent_dhclient = false, + $ethtool_opts = undef, + $bonding_opts = undef, + $isalias = false, + $peerdns = false, + $ipv6peerdns = false, + $dns1 = undef, + $dns2 = undef, + $domain = undef, + $bridge = undef, + $linkdelay = undef, + $scope = undef, + $check_link_down = false, + $flush = false, + $defroute = undef, + $zone = undef, + $metric = undef, + $promisc = false, + $restart = true, + $arpcheck = true, ) { # Validate our booleans validate_bool($noaliasrouting) @@ -163,6 +164,9 @@ $interface = $name + # Normalize $persistent_dhclient value + $persistent_dhclient_real = bool2num($persistent_dhclient) + # Deal with the case where $dns2 is non-empty and $dns1 is empty. if $dns2 { if !$dns1 { diff --git a/spec/defines/network_if_dynamic_spec.rb b/spec/defines/network_if_dynamic_spec.rb index 7ff2336..71f3e70 100644 --- a/spec/defines/network_if_dynamic_spec.rb +++ b/spec/defines/network_if_dynamic_spec.rb @@ -164,5 +164,35 @@ it { should contain_service('network') } end + context 'optional parameters - persistent_dhclient' do + let(:title) { 'eth0' } + let :params do { + :ensure => 'up', + :macaddress => 'bb:cc:bb:cc:bb:cc', + :bootproto => 'dhcp', + :persistent_dhclient => true + } + end + let :facts do { + :osfamily => 'RedHat' + } + end + it { should contain_file('ifcfg-eth0').with( + :ensure => 'present', + :mode => '0644', + :owner => 'root', + :group => 'root', + :path => '/etc/sysconfig/network-scripts/ifcfg-eth0', + :notify => 'Service[network]' + )} + it 'should contain File[ifcfg-eth0] with required contents' do + verify_contents(catalogue, 'ifcfg-eth0', [ + 'DEVICE=eth0', + 'HWADDR=bb:cc:bb:cc:bb:cc', + 'PERSISTENT_DHCLIENT=1' + ]) + end + it { should contain_service('network') } + end end diff --git a/templates/ifcfg-eth.erb b/templates/ifcfg-eth.erb index 2f1addb..8c255fc 100644 --- a/templates/ifcfg-eth.erb +++ b/templates/ifcfg-eth.erb @@ -3,6 +3,9 @@ ### DEVICE=<%= @interface %> BOOTPROTO=<%= @bootproto %> +<% if @bootproto == 'dhcp' -%> +PERSISTENT_DHCLIENT=<%= @persistent_dhclient_real %> +<% end -%> <% if @manage_hwaddr and @macaddress and @macaddress != '' -%> HWADDR=<%= @macaddress %> <% end -%>