From 5f604188a808a02b70d4db6fe25c1e65764238c2 Mon Sep 17 00:00:00 2001 From: Matthias Baur Date: Mon, 22 Jan 2024 10:15:25 +0100 Subject: [PATCH 1/2] systemd::unit_file, Ensure link get's removed on ensure = absent --- manifests/unit_file.pp | 5 ++++- spec/defines/unit_file_spec.rb | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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 From 7f63dfa49850a860b24a93874fe5c5f4430f9edc Mon Sep 17 00:00:00 2001 From: Matthias Baur Date: Thu, 7 Mar 2024 08:53:19 +0100 Subject: [PATCH 2/2] Use stdlib::ensure --- manifests/unit_file.pp | 10 ++-------- metadata.json | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/manifests/unit_file.pp b/manifests/unit_file.pp index 808f4a4e..5d35011e 100644 --- a/manifests/unit_file.pp +++ b/manifests/unit_file.pp @@ -93,15 +93,9 @@ } if $_target { - $_ensure = $ensure ? { - 'absent' => 'absent', - default => 'link', - } + $_ensure = stdlib::ensure($ensure, 'link') } else { - $_ensure = $ensure ? { - 'present' => 'file', - default => $ensure, - } + $_ensure = stdlib::ensure($ensure, 'file') } file { "${path}/${name}": diff --git a/metadata.json b/metadata.json index f82d722d..038a6258 100644 --- a/metadata.json +++ b/metadata.json @@ -10,7 +10,7 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.13.1 < 10.0.0" + "version_requirement": ">= 6.6.0 < 10.0.0" }, { "name": "puppetlabs/inifile",