diff --git a/manifests/resolved.pp b/manifests/resolved.pp index e4b924b6..6b04fdd5 100644 --- a/manifests/resolved.pp +++ b/manifests/resolved.pp @@ -239,25 +239,21 @@ default => $dns_stub_listener, } - if $_dns_stub_listener { - ini_setting { 'dns_stub_listener': - ensure => 'present', - value => $_dns_stub_listener, - setting => 'DNSStubListener', - section => 'Resolve', - path => '/etc/systemd/resolved.conf', - notify => Service['systemd-resolved'], - } + ini_setting { 'dns_stub_listener': + ensure => stdlib::ensure($_dns_stub_listener != undef), + value => $_dns_stub_listener, + setting => 'DNSStubListener', + section => 'Resolve', + path => '/etc/systemd/resolved.conf', + notify => Service['systemd-resolved'], } - if $dns_stub_listener_extra { - ini_setting { 'dns_stub_listener_extra': - ensure => 'present', - value => $dns_stub_listener_extra, - setting => 'DNSStubListenerExtra', - section => 'Resolve', - path => '/etc/systemd/resolved.conf', - notify => Service['systemd-resolved'], - } + ini_setting { 'dns_stub_listener_extra': + ensure => stdlib::ensure($dns_stub_listener_extra != undef), + value => $dns_stub_listener_extra, + setting => 'DNSStubListenerExtra', + section => 'Resolve', + path => '/etc/systemd/resolved.conf', + notify => Service['systemd-resolved'], } } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index af5597c4..29ff8f6c 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -112,7 +112,7 @@ it { is_expected.not_to contain_ini_setting('dnssec') } it { is_expected.not_to contain_ini_setting('dnsovertls') } it { is_expected.not_to contain_ini_setting('cache') } - it { is_expected.not_to contain_ini_setting('dns_stub_listener') } + it { is_expected.to contain_ini_setting('dns_stub_listener').with_ensure('absent') } end context 'when enabling resolved with DNS values (array)' do @@ -134,7 +134,7 @@ it { is_expected.not_to contain_ini_setting('dnssec') } it { is_expected.not_to contain_ini_setting('dnsovertls') } it { is_expected.not_to contain_ini_setting('cache') } - it { is_expected.not_to contain_ini_setting('dns_stub_listener') } + it { is_expected.to contain_ini_setting('dns_stub_listener').with_ensure('absent') } end context 'when enabling resolved with DNS values (full)' do @@ -171,8 +171,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