diff --git a/manifests/unit_file.pp b/manifests/unit_file.pp index 56d120a5..808f4a4e 100644 --- a/manifests/unit_file.pp +++ b/manifests/unit_file.pp @@ -93,7 +93,10 @@ } if $_target { - $_ensure = 'link' + $_ensure = $ensure ? { + 'absent' => 'absent', + default => 'link', + } } else { $_ensure = $ensure ? { 'present' => 'file', diff --git a/spec/defines/unit_file_spec.rb b/spec/defines/unit_file_spec.rb index f693584b..2a087601 100644 --- a/spec/defines/unit_file_spec.rb +++ b/spec/defines/unit_file_spec.rb @@ -184,6 +184,20 @@ expect(subject).not_to create_systemd__daemon_reload(title) } end + + context 'with target => "/tmp/service-target" and ensure => absent' do + let(:params) do + { ensure: 'absent', target: '/tmp/service-target' } + end + + it { is_expected.to compile.with_all_deps } + + it do + expect(subject).to create_file("/etc/systemd/system/#{title}"). + with_ensure('absent'). + with_target('/tmp/service-target') + end + end end end end