From 2108137966e43238bb386528c875285d1441392f Mon Sep 17 00:00:00 2001 From: Tamerz Date: Sun, 29 Aug 2021 11:58:25 +0300 Subject: [PATCH 1/2] Adding chroot_dir_manage parameter. --- manifests/config.pp | 13 ++++++++----- manifests/instance.pp | 6 ++++++ spec/defines/instance_spec.rb | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index d29462c6..2b5b4a9b 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -8,6 +8,7 @@ $global_options, $defaults_options, $package_ensure, + $chroot_dir_manage, $config_dir = undef, # A default is required for Puppet 2.7 compatibility. When 2.7 is no longer supported, this parameter default should be removed. $custom_fragment = undef, # A default is required for Puppet 2.7 compatibility. When 2.7 is no longer supported, this parameter default should be removed. $merge_options = $haproxy::merge_options, @@ -77,11 +78,13 @@ } } - if $_global_options['chroot'] { - file { $_global_options['chroot']: - ensure => directory, - owner => $_global_options['user'], - group => $_global_options['group'], + if $chroot_dir_manage { + if $_global_options['chroot'] { + file { $_global_options['chroot']: + ensure => directory, + owner => $_global_options['user'], + group => $_global_options['group'], + } } } } diff --git a/manifests/instance.pp b/manifests/instance.pp index d6a04301..4db09980 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -27,6 +27,10 @@ # Chooses whether the haproxy service state should be managed by puppet at # all. Defaults to true # +# @param chroot_dir_manage +# Chooses whether the haproxy chroot directory should be managed by puppet +# at all. Defaults to true +# # @param service_name # The service name for haproxy. Defaults to undef. If no name is given then # the value computed for $instance_name will be used. @@ -159,6 +163,7 @@ String[1] $package_ensure = 'present', Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running', Boolean $service_manage = true, + Boolean $chroot_dir_manage = true, Optional[String] $service_name = undef, Optional[Hash] $global_options = undef, Optional[Hash] $defaults_options = undef, @@ -215,6 +220,7 @@ custom_fragment => $custom_fragment, merge_options => $merge_options, package_ensure => $package_ensure, + chroot_dir_manage => $chroot_dir_manage, config_validate_cmd => $config_validate_cmd, } haproxy::install { $title: diff --git a/spec/defines/instance_spec.rb b/spec/defines/instance_spec.rb index aaa795d2..029d29f4 100644 --- a/spec/defines/instance_spec.rb +++ b/spec/defines/instance_spec.rb @@ -222,6 +222,20 @@ end end end + context "when on #{osfamily} family operatingsystems without managing the chroot directory" do + let(:facts) do + { osfamily: osfamily }.merge default_facts + end + let(:params) do + { + 'chroot_dir_manage' => false, + } + end + + it 'does not manage the haproxy chroot directory' do + subject.should_not contain_file('/var/lib/haproxy') + end + end context "on #{osfamily} when specifying a restart_command" do let(:facts) do { osfamily: osfamily }.merge default_facts From 408f6d35fb5d535b9d6ba8b37407f11a0b1a2a34 Mon Sep 17 00:00:00 2001 From: Tamerz Date: Sun, 29 Aug 2021 16:10:36 +0300 Subject: [PATCH 2/2] Added chroot_dir_manage parameter to init class. --- manifests/init.pp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index 3ab03ca3..4cb94f08 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -32,6 +32,10 @@ # @param service_options # Contents for the `/etc/defaults/haproxy` file on Debian. Defaults to "ENABLED=1\n" on Debian, and is ignored on other systems. # +# @param chroot_dir_manage +# Chooses whether the haproxy chroot directory should be managed by puppet +# at all. Defaults to true +# # @param sysconfig_options # Contents for the `/etc/sysconfig/haproxy` file on RedHat(-based) systems. # Defaults to OPTIONS="" on RedHat(-based) systems and is ignored on others @@ -120,6 +124,7 @@ String $package_name = $haproxy::params::package_name, Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running', Boolean $service_manage = true, + Boolean $chroot_dir_manage = true, String $service_name = $haproxy::params::service_name, String $service_options = $haproxy::params::service_options, $sysconfig_options = $haproxy::params::sysconfig_options, @@ -172,6 +177,7 @@ service_ensure => $_service_ensure, service_manage => $_service_manage, service_name => $service_name, + chroot_dir_manage => $chroot_dir_manage, global_options => $global_options, defaults_options => $defaults_options, restart_command => $restart_command,