From: Peter Palfrader Date: Wed, 25 Sep 2019 11:05:06 +0000 (+0200) Subject: dsa_systemd::override: cleanup and make sure removal cleans the dir also X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=4eacb834d9a191b221d0d021c7153f0bbce41c7f;p=mirror%2Fdsa-puppet.git dsa_systemd::override: cleanup and make sure removal cleans the dir also --- diff --git a/modules/dsa_systemd/manifests/override.pp b/modules/dsa_systemd/manifests/override.pp index b2d210f11..f05ab47f4 100644 --- a/modules/dsa_systemd/manifests/override.pp +++ b/modules/dsa_systemd/manifests/override.pp @@ -1,54 +1,32 @@ +# declare a systemd service override +# @param content content of systemd override file +# @param source source of systemd override file content +# @param ensure present or avsent define dsa_systemd::override ( - $source=undef, - $content=undef, - $ensure=present + Optional[String] $source = undef, + Optional[String] $content = undef, + Enum['present','absent'] $ensure = 'present', ) { + $dir = "/etc/systemd/system/${name}.service.d" + $dest = "${dir}/override.conf" - $dir = "/etc/systemd/system/${name}.service.d" - $dest = "${dir}/override.conf" - case $ensure { - present: { - if ! ($source or $content) { - fail ( "No configuration found for ${name}" ) - } - file { "${dir}": - ensure => directory, - mode => '0755' - } - if $content { - file { "${dest}": - ensure => $ensure, - content => $content, - notify => [ Exec['systemctl daemon-reload'], - Service["${name}"], - ] - } - } elsif $source { - file { "${dest}": - ensure => $ensure, - source => $source, - notify => [ Exec['systemctl daemon-reload'], - Service["${name}"], - ] - } - } - } - absent: { - if defined(Service["${name}"]) { - $notify = [ Exec['systemctl daemon-reload'], Service["${name}"] ] - } else { - $notify = [ Exec['systemctl daemon-reload'] ] - } + if defined(Service[$name]) { + $notify = [ Exec['systemctl daemon-reload'], Service[$name] ] + } else { + $notify = [ Exec['systemctl daemon-reload'] ] + } - file { "${dest}": - ensure => $ensure, - notify => $notify, - } - file { "${dir}": - ensure => $ensure - } - } - default: { fail ( "Unknown ensure value: '$ensure'" ) } - } + $directory_ensure = $ensure ? { 'present' => 'directory', 'absent' => 'absent' } + file { $dir: + ensure => $directory_ensure, + mode => '0755', + force => true, + } + file { $dest: + ensure => $ensure, + source => $source, + content => $content, + notify => $notify, + } }