Skip to content

Commit

Permalink
Add support for static DNS servers when using the DHCP client
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuller committed Feb 19, 2018
1 parent 106d300 commit 8d8c48a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
10 changes: 10 additions & 0 deletions manifests/if/dynamic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,6 +57,8 @@
$dhcp_hostname = undef,
$ethtool_opts = undef,
$peerdns = false,
$dns1 = undef,
$dns2 = undef,
$linkdelay = undef,
$check_link_down = false,
$defroute = undef,
Expand All @@ -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 => '',
Expand All @@ -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,
Expand Down
33 changes: 33 additions & 0 deletions spec/defines/network_if_dynamic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,38 @@
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',
:macaddress => 'bb:cc:bb:cc:bb:cc'
}
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',
'HWADDR=bb:cc:bb:cc:bb:cc'
])
end
it { should contain_service('network') }
end

end

0 comments on commit 8d8c48a

Please sign in to comment.