diff --git a/README.md b/README.md index 3d167aa..26d3769 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,15 @@ Normal interface - dhcp: ethtool_opts => 'autoneg off speed 100 duplex full', } +Normal interface - dhcp with custom DNS servers (peerdns must be true): + + network::if::dynamic { 'eth0': + ensure => 'up', + peerdns => true, + dns1 => '8.8.8.8', + dns2 => '8.8.4.4', + } + Normal interface - bootp (minimal): network::if::dynamic { 'eth2': diff --git a/manifests/if/dynamic.pp b/manifests/if/dynamic.pp index 1bc4b16..8814b29 100644 --- a/manifests/if/dynamic.pp +++ b/manifests/if/dynamic.pp @@ -13,6 +13,8 @@ # $dhcp_hostname - optional # $ethtool_opts - optional # $peerdns - optional +# $dns1 - optional - only used when peerdns is true +# $dns2 - optional - only used when peerdns is true # $linkdelay - optional # $check_link_down - optional # $zone - optional @@ -55,6 +57,8 @@ $dhcp_hostname = undef, $ethtool_opts = undef, $peerdns = false, + $dns1 = undef, + $dns2 = undef, $linkdelay = undef, $check_link_down = false, $defroute = undef, @@ -78,6 +82,10 @@ validate_bool($peerdns) validate_bool($manage_hwaddr) + if !$peerdns and ($dns1 or $dns2) { + fail('$peerdns must be true when $dns1 or $dns2 are specified') + } + network_if_base { $title: ensure => $ensure, ipaddress => '', @@ -91,6 +99,8 @@ dhcp_hostname => $dhcp_hostname, ethtool_opts => $ethtool_opts, peerdns => $peerdns, + dns1 => $dns1, + dns2 => $dns2, linkdelay => $linkdelay, check_link_down => $check_link_down, defroute => $defroute, diff --git a/spec/defines/network_if_dynamic_spec.rb b/spec/defines/network_if_dynamic_spec.rb index 7ff2336..1d750fb 100644 --- a/spec/defines/network_if_dynamic_spec.rb +++ b/spec/defines/network_if_dynamic_spec.rb @@ -164,5 +164,36 @@ it { should contain_service('network') } end + context 'optional parameters - static dns' do + let(:title) { 'eth0' } + let :params do { + :ensure => 'up', + :peerdns => true, + :dns1 => '8.8.8.8', + :dns2 => '8.8.4.4' + } + 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', + 'PEERDNS=yes', + 'DNS1=8.8.8.8', + 'DNS2=8.8.4.4' + ]) + end + it { should contain_service('network') } + end end