Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No insistence on unit_entry ever or service_entry with absent manage_unit #345

Merged
merged 1 commit into from Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion REFERENCE.md
Expand Up @@ -1037,6 +1037,13 @@ systemd::manage_unit{'arcd@.service':
'ExecStart' => /usr/sbin/arcd /usr/libexec/arcd/arcd.pl,
'StandardInput' => 'socket',
}
```

##### Remove a unit file

```puppet
systemd::manage_unit { 'my.service':
ensure => 'absent',
}
```

Expand Down Expand Up @@ -1168,10 +1175,12 @@ Default value: `true`

##### <a name="-systemd--manage_unit--unit_entry"></a>`unit_entry`

Data type: `Systemd::Unit::Unit`
Data type: `Optional[Systemd::Unit::Unit]`

key value pairs for [Unit] section of the unit file.

Default value: `undef`

##### <a name="-systemd--manage_unit--service_entry"></a>`service_entry`

Data type: `Optional[Systemd::Unit::Service]`
Expand Down
10 changes: 7 additions & 3 deletions manifests/manage_unit.pp
Expand Up @@ -61,6 +61,10 @@
# 'ExecStart' => /usr/sbin/arcd /usr/libexec/arcd/arcd.pl,
# 'StandardInput' => 'socket',
# }
#
# @example Remove a unit file
# systemd::manage_unit { 'my.service':
# ensure => 'absent',
# }
#
# @param name [Pattern['^[^/]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$']]
Expand Down Expand Up @@ -103,7 +107,7 @@
Hash[String[1], Any] $service_parameters = {},
Boolean $daemon_reload = true,
Optional[Systemd::Unit::Install] $install_entry = undef,
Systemd::Unit::Unit $unit_entry,
Optional[Systemd::Unit::Unit] $unit_entry = undef,
Optional[Systemd::Unit::Service] $service_entry = undef,
Optional[Systemd::Unit::Timer] $timer_entry = undef,
Optional[Systemd::Unit::Path] $path_entry = undef,
Expand All @@ -119,8 +123,8 @@
fail("Systemd::Manage_unit[${name}]: path_entry is only valid for path units")
}

if $name =~ Pattern['^[^/]+\.service'] and !$service_entry {
fail("Systemd::Manage_unit[${name}]: service_entry is only required for service units")
if $ensure != 'absent' and $name =~ Pattern['^[^/]+\.service'] and !$service_entry {
fail("Systemd::Manage_unit[${name}]: service_entry is required for service units")
}

systemd::unit_file { $name:
Expand Down
18 changes: 18 additions & 0 deletions spec/defines/manage_unit_spec.rb
Expand Up @@ -42,6 +42,24 @@
with_content(%r{^Type=oneshot$})
}

context 'with no service_entry' do
let(:params) do
{
ensure: 'present',
}
end

it { is_expected.to compile.and_raise_error(%r{service_entry is required for service units}) }

context 'with ensure absent' do
let(:params) do
super().merge(ensure: 'absent')
end

it { is_expected.to contain_systemd__unit_file('foobar.service').with_ensure('absent') }
end
end

context 'with a timer entry' do
let(:params) do
super().merge(timer_entry: { 'OnCalendar' => 'something' })
Expand Down