Skip to content

Commit

Permalink
Merge pull request #405 from voxpupuli/unit_file_ensure_absent_link
Browse files Browse the repository at this point in the history
`systemd::unit_file`: Ensure link gets removed on `ensure => absent`
  • Loading branch information
baurmatt authored Mar 11, 2024
2 parents 51c0d2c + 7f63dfa commit b72cca8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 2 additions & 5 deletions manifests/unit_file.pp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,9 @@
}

if $_target {
$_ensure = 'link'
$_ensure = stdlib::ensure($ensure, 'link')
} else {
$_ensure = $ensure ? {
'present' => 'file',
default => $ensure,
}
$_ensure = stdlib::ensure($ensure, 'file')
}

file { "${path}/${name}":
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions spec/defines/unit_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b72cca8

Please sign in to comment.