From ea31bc35094ab02064c1181873dc8efb07136304 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 21 May 2024 12:24:50 +0200 Subject: [PATCH] ensure! --- manifests/config.pp | 27 +++++++++---------- manifests/service.pp | 62 ++++++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 1149fbaf..506285d9 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -98,13 +98,12 @@ ) ) $min_puma_threads = pick($foreman::foreman_service_puma_threads_min, $foreman::foreman_service_puma_threads_max) - if $foreman::deployment_mode == 'package' { - systemd::dropin_file { 'foreman-service': - filename => 'installer.conf', - unit => "${foreman::foreman_service}.service", - content => template('foreman/foreman.service-overrides.erb'), - notify_service => true, - } + systemd::dropin_file { 'foreman-service': + ensure => bool2str($foreman::deployment_mode == 'package', 'present', 'absent'), + filename => 'installer.conf', + unit => "${foreman::foreman_service}.service", + content => template('foreman/foreman.service-overrides.erb'), + notify_service => true, } if ! defined(File[$foreman::app_root]) { @@ -288,13 +287,11 @@ $foreman_socket_override = undef } - if $foreman::deployment_mode == 'package' { - systemd::dropin_file { 'foreman-socket': - ensure => bool2str($foreman_socket_override =~ Undef, 'absent', 'present'), - filename => 'installer.conf', - unit => "${foreman::foreman_service}.socket", - content => $foreman_socket_override, - notify_service => true, - } + systemd::dropin_file { 'foreman-socket': + ensure => bool2str($foreman_socket_override =~ Undef or $foreman::deployment_mode != 'package', 'absent', 'present'), + filename => 'installer.conf', + unit => "${foreman::foreman_service}.socket", + content => $foreman_socket_override, + notify_service => true, } } diff --git a/manifests/service.pp b/manifests/service.pp index d63ad74c..3f8e5398 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -37,41 +37,47 @@ } } - if $deployment_mode == 'package' { - service { "${foreman_service}.socket": - ensure => $foreman_service_ensure, - enable => $foreman_service_enable, - } + service { "${foreman_service}.socket": + ensure => bool2str($deployment_mode == 'package', $foreman_service_ensure, 'absent'), + enable => $foreman_service_enable, + } - service { $foreman_service: + if $deployment_mode == 'package' { + # podman::quadlet already creates a service with the same name + service { "${foreman_service}.service": ensure => $foreman_service_ensure, enable => $foreman_service_enable, before => Service["${foreman_service}.socket"], } - } else { + } + + if $deployment_mode == 'container' { file { '/etc/containers/systemd': ensure => directory, } - podman::quadlet { 'foreman.container': - ensure => present, - unit_entry => { - 'Description' => 'Foreman', - }, - service_entry => { - 'TimeoutStartSec' => '900', - }, - container_entry => { - 'Image' => $container_image, - 'Volume' => ['/etc/foreman/:/etc/foreman/'], - 'AddCapability' => ['CAP_DAC_OVERRIDE', 'CAP_IPC_OWNER'], - 'Network' => 'host', - 'HostName' => $foreman::servername, - 'Notify' => true, - }, - install_entry => { - 'WantedBy' => 'default.target', - }, - active => true, - } + } + + $quadlet_active = $deployment_mode ? { 'container' => true, default => undef } + + podman::quadlet { 'foreman.container': + ensure => bool2str($deployment_mode == 'container', 'present', 'absent'), + unit_entry => { + 'Description' => 'Foreman', + }, + service_entry => { + 'TimeoutStartSec' => '900', + }, + container_entry => { + 'Image' => $container_image, + 'Volume' => ['/etc/foreman/:/etc/foreman/'], + 'AddCapability' => ['CAP_DAC_OVERRIDE', 'CAP_IPC_OWNER'], + 'Network' => 'host', + 'HostName' => $foreman::servername, + 'Notify' => true, + }, + install_entry => { + 'WantedBy' => 'default.target', + }, + active => $quadlet_active, } }