Skip to content

Commit d0a5c82

Browse files
committed
Add support for static DNS servers when using the DHCP client
1 parent 106d300 commit d0a5c82

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ Normal interface - dhcp:
107107
ethtool_opts => 'autoneg off speed 100 duplex full',
108108
}
109109

110+
Normal interface - dhcp with custom DNS servers (peerdns must be true):
111+
112+
network::if::dynamic { 'eth0':
113+
ensure => 'up',
114+
peerdns => true,
115+
dns1 => '8.8.8.8',
116+
dns2 => '8.8.4.4',
117+
}
118+
110119
Normal interface - bootp (minimal):
111120

112121
network::if::dynamic { 'eth2':

manifests/if/dynamic.pp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# $dhcp_hostname - optional
1414
# $ethtool_opts - optional
1515
# $peerdns - optional
16+
# $dns1 - optional - only used when peerdns is true
17+
# $dns2 - optional - only used when peerdns is true
1618
# $linkdelay - optional
1719
# $check_link_down - optional
1820
# $zone - optional
@@ -55,6 +57,8 @@
5557
$dhcp_hostname = undef,
5658
$ethtool_opts = undef,
5759
$peerdns = false,
60+
$dns1 = undef,
61+
$dns2 = undef,
5862
$linkdelay = undef,
5963
$check_link_down = false,
6064
$defroute = undef,
@@ -78,6 +82,10 @@
7882
validate_bool($peerdns)
7983
validate_bool($manage_hwaddr)
8084

85+
if !$peerdns and ($dns1 or $dns2) {
86+
fail('$peerdns must be true when $dns1 or $dns2 are specified')
87+
}
88+
8189
network_if_base { $title:
8290
ensure => $ensure,
8391
ipaddress => '',
@@ -91,6 +99,8 @@
9199
dhcp_hostname => $dhcp_hostname,
92100
ethtool_opts => $ethtool_opts,
93101
peerdns => $peerdns,
102+
dns1 => $dns1,
103+
dns2 => $dns2,
94104
linkdelay => $linkdelay,
95105
check_link_down => $check_link_down,
96106
defroute => $defroute,

spec/defines/network_if_dynamic_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,38 @@
164164
it { should contain_service('network') }
165165
end
166166

167+
context 'optional parameters - static dns' do
168+
let(:title) { 'eth0' }
169+
let :params do {
170+
:ensure => 'up',
171+
:peerdns => true,
172+
:dns1 => '8.8.8.8',
173+
:dns2 => '8.8.4.4',
174+
:macaddress_eth0 => 'bb:cc:bb:cc:bb:cc'
175+
}
176+
end
177+
let :facts do {
178+
:osfamily => 'RedHat'
179+
}
180+
end
181+
it { should contain_file('ifcfg-eth0').with(
182+
:ensure => 'present',
183+
:mode => '0644',
184+
:owner => 'root',
185+
:group => 'root',
186+
:path => '/etc/sysconfig/network-scripts/ifcfg-eth0',
187+
:notify => 'Service[network]'
188+
)}
189+
it 'should contain File[ifcfg-eth0] with required contents' do
190+
verify_contents(catalogue, 'ifcfg-eth0', [
191+
'DEVICE=eth0',
192+
'PEERDNS=yes',
193+
'DNS1=8.8.8.8',
194+
'DNS2=8.8.4.4',
195+
'HWADDR=bb:cc:bb:cc:bb:cc'
196+
])
197+
end
198+
it { should contain_service('network') }
199+
end
167200

168201
end

0 commit comments

Comments
 (0)