Skip to content

Commit 9dbf780

Browse files
TheMeierbastelfreak
andcommitted
remove resovled settings from config when changed to undef
fixes #397 Co-authored-by: Tim Meusel <[email protected]>
1 parent 51c0d2c commit 9dbf780

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
@@ -294,17 +294,19 @@ Default value: `undef`
294294

295295
##### <a name="-systemd--dns_stub_listener"></a>`dns_stub_listener`
296296

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

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

301302
Default value: `undef`
302303

303304
##### <a name="-systemd--dns_stub_listener_extra"></a>`dns_stub_listener_extra`
304305

305-
Data type: `Optional[Array[String[1]]]`
306+
Data type: `Optional[Variant[Array[String[1]],Enum['absent']]]`
306307

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

309311
Default value: `undef`
310312

manifests/init.pp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@
6565
#
6666
# @param dns_stub_listener
6767
# Takes a boolean argument or one of "udp" and "tcp".
68+
# Setting it to `'absent'` will remove `DNSStubListener` existing entries from the configuration file
6869
#
6970
# @param dns_stub_listener_extra
7071
# Additional addresses for the DNS stub listener to listen on
72+
# Setting it to `'absent'` will remove `DNSStubListenerExtra` existing entries from the configuration file
7173
#
7274
# @param manage_resolv_conf
7375
# For when `manage_resolved` is `true` should the file `/etc/resolv.conf` be managed.
@@ -204,8 +206,8 @@
204206
Optional[Variant[Boolean,Enum['allow-downgrade']]] $dnssec = undef,
205207
Variant[Boolean,Enum['yes', 'opportunistic', 'no']] $dnsovertls = false,
206208
Optional[Variant[Boolean,Enum['no-negative']]] $cache = undef,
207-
Optional[Variant[Boolean,Enum['udp','tcp']]] $dns_stub_listener = undef,
208-
Optional[Array[String[1]]] $dns_stub_listener_extra = undef,
209+
Optional[Variant[Boolean,Enum['udp','tcp','absent']]] $dns_stub_listener = undef,
210+
Optional[Variant[Array[String[1]],Enum['absent']]] $dns_stub_listener_extra = undef,
209211
Boolean $manage_resolv_conf = true,
210212
Boolean $use_stub_resolver = false,
211213
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
@@ -137,6 +137,36 @@
137137
it { is_expected.not_to contain_ini_setting('dns_stub_listener') }
138138
end
139139

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

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

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

0 commit comments

Comments
 (0)