Skip to content

Commit

Permalink
remove resovled settings from config when changed to undef
Browse files Browse the repository at this point in the history
fixes #397
  • Loading branch information
TheMeier committed Mar 11, 2024
1 parent 51c0d2c commit 56c41ad
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
4 changes: 3 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,10 @@ Default value: `undef`

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

Data type: `Optional[Variant[Boolean,Enum['udp','tcp']]]`
Data type: `Optional[Variant[Boolean,Enum['udp','tcp','absent']]]`

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

Default value: `undef`

Expand All @@ -305,6 +306,7 @@ Default value: `undef`
Data type: `Optional[Array[String[1]]]`

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

Default value: `undef`

Expand Down
4 changes: 3 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@
#
# @param dns_stub_listener
# Takes a boolean argument or one of "udp" and "tcp".
# Setting it to 'absent' will remove `DNSStubListener` existing entries from the configuration file-
#
# @param dns_stub_listener_extra
# Additional addresses for the DNS stub listener to listen on
# Setting it to 'absent' will remove `DNSStubListenerExtra` existing entries from the configuration file-
#
# @param manage_resolv_conf
# For when `manage_resolved` is `true` should the file `/etc/resolv.conf` be managed.
Expand Down Expand Up @@ -204,7 +206,7 @@
Optional[Variant[Boolean,Enum['allow-downgrade']]] $dnssec = undef,
Variant[Boolean,Enum['yes', 'opportunistic', 'no']] $dnsovertls = false,
Optional[Variant[Boolean,Enum['no-negative']]] $cache = undef,
Optional[Variant[Boolean,Enum['udp','tcp']]] $dns_stub_listener = undef,
Optional[Variant[Boolean,Enum['udp','tcp','absent']]] $dns_stub_listener = undef,
Optional[Array[String[1]]] $dns_stub_listener_extra = undef,
Boolean $manage_resolv_conf = true,
Boolean $use_stub_resolver = false,
Expand Down
12 changes: 6 additions & 6 deletions manifests/resolved.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
Optional[Variant[Boolean,Enum['resolve']]] $multicast_dns = $systemd::multicast_dns,
Optional[Variant[Boolean,Enum['allow-downgrade']]] $dnssec = $systemd::dnssec,
Optional[Variant[Boolean,Enum['yes', 'opportunistic', 'no']]] $dnsovertls = $systemd::dnsovertls,
Optional[Variant[Boolean,Enum['no-negative']]] $cache = $systemd::cache,
Optional[Variant[Boolean,Enum['udp', 'tcp']]] $dns_stub_listener = $systemd::dns_stub_listener,
Optional[Variant[Boolean,Enum['no-negative']]] $cache = $systemd::cache,
Optional[Variant[Boolean,Enum['udp', 'tcp','absent']]] $dns_stub_listener = $systemd::dns_stub_listener,
Optional[Array[String[1]]] $dns_stub_listener_extra = $systemd::dns_stub_listener_extra,
Boolean $use_stub_resolver = $systemd::use_stub_resolver,
) {
Expand Down Expand Up @@ -239,9 +239,9 @@
default => $dns_stub_listener,
}

if $_dns_stub_listener {
if $dns_stub_listener =~ String[1] {
ini_setting { 'dns_stub_listener':
ensure => 'present',
ensure => stdlib::ensure($dns_stub_listener != 'absent'),
value => $_dns_stub_listener,
setting => 'DNSStubListener',
section => 'Resolve',
Expand All @@ -250,9 +250,9 @@
}
}

if $dns_stub_listener_extra {
if $dns_stub_listener_extra =~ NotUndef {
ini_setting { 'dns_stub_listener_extra':
ensure => 'present',
ensure => stdlib::ensure($dns_stub_listener_extra[0] != 'absent'),
value => $dns_stub_listener_extra,
setting => 'DNSStubListenerExtra',
section => 'Resolve',
Expand Down
39 changes: 37 additions & 2 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,36 @@
it { is_expected.not_to contain_ini_setting('dns_stub_listener') }
end

context 'when setting dns_stub_listener to absent' do
let(:params) do
{
manage_resolved: true,
dns: ['8.8.8.8', '8.8.4.4'],
fallback_dns: ['2001:4860:4860::8888', '2001:4860:4860::8844'],
dns_stub_listener: 'absent'
}
end

it { is_expected.to create_service('systemd-resolved').with_ensure('running') }
it { is_expected.to create_service('systemd-resolved').with_enable(true) }
it { is_expected.to contain_ini_setting('dns_stub_listener').with_ensure('absent') }
end

context 'when setting dns_stub_listener_extra to absent' do
let(:params) do
{
manage_resolved: true,
dns: ['8.8.8.8', '8.8.4.4'],
fallback_dns: ['2001:4860:4860::8888', '2001:4860:4860::8844'],
dns_stub_listener_extra: ['absent']
}
end

it { is_expected.to create_service('systemd-resolved').with_ensure('running') }
it { is_expected.to create_service('systemd-resolved').with_enable(true) }
it { is_expected.to contain_ini_setting('dns_stub_listener_extra').with_ensure('absent') }
end

context 'when enabling resolved with DNS values (full)' do
let(:params) do
{
Expand Down Expand Up @@ -171,8 +201,13 @@
)
}

it { is_expected.to contain_ini_setting('dns_stub_listener') }
it { is_expected.to contain_ini_setting('dns_stub_listener_extra').with_value(['192.0.2.1', '2001:db8::1']) }
it { is_expected.to contain_ini_setting('dns_stub_listener').with_ensure('present') }

it {
is_expected.to contain_ini_setting('dns_stub_listener_extra').
with_value(['192.0.2.1', '2001:db8::1']).
with_ensure('present')
}
end

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

0 comments on commit 56c41ad

Please sign in to comment.