Skip to content

Commit 9e330f9

Browse files
authored
Merge pull request #429 from /issues/397
remove resolved settings from config when changed to `absent`
2 parents f12baf7 + 9dbf780 commit 9e330f9

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

REFERENCE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,19 @@ Default value: `undef`
315315

316316
##### <a name="-systemd--dns_stub_listener"></a>`dns_stub_listener`
317317

318-
Data type: `Optional[Variant[Boolean,Enum['udp','tcp']]]`
318+
Data type: `Optional[Variant[Boolean,Enum['udp','tcp','absent']]]`
319319

320320
Takes a boolean argument or one of "udp" and "tcp".
321+
Setting it to `'absent'` will remove `DNSStubListener` existing entries from the configuration file
321322

322323
Default value: `undef`
323324

324325
##### <a name="-systemd--dns_stub_listener_extra"></a>`dns_stub_listener_extra`
325326

326-
Data type: `Optional[Array[String[1]]]`
327+
Data type: `Optional[Variant[Array[String[1]],Enum['absent']]]`
327328

328329
Additional addresses for the DNS stub listener to listen on
330+
Setting it to `'absent'` will remove `DNSStubListenerExtra` existing entries from the configuration file
329331

330332
Default value: `undef`
331333

manifests/init.pp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@
7171
#
7272
# @param dns_stub_listener
7373
# Takes a boolean argument or one of "udp" and "tcp".
74+
# Setting it to `'absent'` will remove `DNSStubListener` existing entries from the configuration file
7475
#
7576
# @param dns_stub_listener_extra
7677
# Additional addresses for the DNS stub listener to listen on
78+
# Setting it to `'absent'` will remove `DNSStubListenerExtra` existing entries from the configuration file
7779
#
7880
# @param manage_resolv_conf
7981
# For when `manage_resolved` is `true` should the file `/etc/resolv.conf` be managed.
@@ -216,8 +218,8 @@
216218
Optional[Variant[Boolean,Enum['allow-downgrade']]] $dnssec = undef,
217219
Variant[Boolean,Enum['yes', 'opportunistic', 'no']] $dnsovertls = false,
218220
Optional[Variant[Boolean,Enum['no-negative']]] $cache = undef,
219-
Optional[Variant[Boolean,Enum['udp','tcp']]] $dns_stub_listener = undef,
220-
Optional[Array[String[1]]] $dns_stub_listener_extra = undef,
221+
Optional[Variant[Boolean,Enum['udp','tcp','absent']]] $dns_stub_listener = undef,
222+
Optional[Variant[Array[String[1]],Enum['absent']]] $dns_stub_listener_extra = undef,
221223
Boolean $manage_resolv_conf = true,
222224
Boolean $use_stub_resolver = false,
223225
Boolean $manage_networkd = false,

manifests/resolved.pp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
Optional[Variant[Boolean,Enum['resolve']]] $multicast_dns = $systemd::multicast_dns,
5858
Optional[Variant[Boolean,Enum['allow-downgrade']]] $dnssec = $systemd::dnssec,
5959
Optional[Variant[Boolean,Enum['yes', 'opportunistic', 'no']]] $dnsovertls = $systemd::dnsovertls,
60-
Optional[Variant[Boolean,Enum['no-negative']]] $cache = $systemd::cache,
61-
Optional[Variant[Boolean,Enum['udp', 'tcp']]] $dns_stub_listener = $systemd::dns_stub_listener,
62-
Optional[Array[String[1]]] $dns_stub_listener_extra = $systemd::dns_stub_listener_extra,
60+
Optional[Variant[Boolean,Enum['no-negative']]] $cache = $systemd::cache,
61+
Optional[Variant[Boolean,Enum['udp', 'tcp','absent']]] $dns_stub_listener = $systemd::dns_stub_listener,
62+
Optional[Variant[Array[String[1]],Enum['absent']]] $dns_stub_listener_extra = $systemd::dns_stub_listener_extra,
6363
Boolean $use_stub_resolver = $systemd::use_stub_resolver,
6464
) {
6565
assert_private()
@@ -239,9 +239,9 @@
239239
default => $dns_stub_listener,
240240
}
241241

242-
if $_dns_stub_listener {
242+
if $dns_stub_listener =~ String[1] {
243243
ini_setting { 'dns_stub_listener':
244-
ensure => 'present',
244+
ensure => stdlib::ensure($dns_stub_listener != 'absent'),
245245
value => $_dns_stub_listener,
246246
setting => 'DNSStubListener',
247247
section => 'Resolve',
@@ -250,9 +250,9 @@
250250
}
251251
}
252252

253-
if $dns_stub_listener_extra {
253+
if $dns_stub_listener_extra =~ NotUndef {
254254
ini_setting { 'dns_stub_listener_extra':
255-
ensure => 'present',
255+
ensure => stdlib::ensure($dns_stub_listener_extra != 'absent'),
256256
value => $dns_stub_listener_extra,
257257
setting => 'DNSStubListenerExtra',
258258
section => 'Resolve',

spec/classes/init_spec.rb

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,36 @@
138138
it { is_expected.not_to contain_ini_setting('dns_stub_listener') }
139139
end
140140

141+
context 'when setting dns_stub_listener to absent' do
142+
let(:params) do
143+
{
144+
manage_resolved: true,
145+
dns: ['8.8.8.8', '8.8.4.4'],
146+
fallback_dns: ['2001:4860:4860::8888', '2001:4860:4860::8844'],
147+
dns_stub_listener: 'absent'
148+
}
149+
end
150+
151+
it { is_expected.to create_service('systemd-resolved').with_ensure('running') }
152+
it { is_expected.to create_service('systemd-resolved').with_enable(true) }
153+
it { is_expected.to contain_ini_setting('dns_stub_listener').with_ensure('absent') }
154+
end
155+
156+
context 'when setting dns_stub_listener_extra to absent' do
157+
let(:params) do
158+
{
159+
manage_resolved: true,
160+
dns: ['8.8.8.8', '8.8.4.4'],
161+
fallback_dns: ['2001:4860:4860::8888', '2001:4860:4860::8844'],
162+
dns_stub_listener_extra: 'absent'
163+
}
164+
end
165+
166+
it { is_expected.to create_service('systemd-resolved').with_ensure('running') }
167+
it { is_expected.to create_service('systemd-resolved').with_enable(true) }
168+
it { is_expected.to contain_ini_setting('dns_stub_listener_extra').with_ensure('absent') }
169+
end
170+
141171
context 'when enabling resolved with DNS values (full)' do
142172
let(:params) do
143173
{
@@ -172,8 +202,13 @@
172202
)
173203
}
174204

175-
it { is_expected.to contain_ini_setting('dns_stub_listener') }
176-
it { is_expected.to contain_ini_setting('dns_stub_listener_extra').with_value(['192.0.2.1', '2001:db8::1']) }
205+
it { is_expected.to contain_ini_setting('dns_stub_listener').with_ensure('present') }
206+
207+
it {
208+
is_expected.to contain_ini_setting('dns_stub_listener_extra').
209+
with_value(['192.0.2.1', '2001:db8::1']).
210+
with_ensure('present')
211+
}
177212
end
178213

179214
context 'when enabling resolved with no-negative cache variant' do

0 commit comments

Comments
 (0)