From fdd43ea15173e45358b6fbef718e65ee9fdaa203 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Fri, 10 Dec 2021 21:48:40 +0100 Subject: [PATCH 1/4] make workdir_owner and group a parameter --- manifests/config.pp | 4 ++-- manifests/init.pp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index beedbdc7..82054281 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -21,9 +21,9 @@ file { $redis::workdir: ensure => directory, - group => $redis::service_group, + group => pick($redis::workdir_group, $redis::service_group), mode => $redis::workdir_mode, - owner => $redis::service_user, + owner => pick($redis::workdir_owner, $redis::service_user), } if $redis::default_install { diff --git a/manifests/init.pp b/manifests/init.pp index 0de065df..312caeb3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -263,6 +263,10 @@ # above using the 'dbfilename' configuration directive. # @param workdir_mode # Adjust mode for data directory. +# @param workdir_group +# Adjust filesystem group for $workdir. +# @param workdir_owner +# Adjust filesystem owner for $workdir. # @param zset_max_ziplist_entries # Set max entries for sorted sets. # @param zset_max_ziplist_value @@ -455,6 +459,8 @@ Boolean $ulimit_managed = true, Stdlib::Absolutepath $workdir = $redis::params::workdir, Stdlib::Filemode $workdir_mode = '0750', + Optional[String[1]] $workdir_group = undef, + Optional[String[1]] $workdir_owner = undef, Integer[0] $zset_max_ziplist_entries = 128, Integer[0] $zset_max_ziplist_value = 64, Boolean $cluster_enabled = false, From 24c72d8f6b6660d629c786220fd5acf49f1aa933 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Sat, 11 Dec 2021 12:49:53 +0100 Subject: [PATCH 2/4] add parameters for /etc/default/redis ownership on debian --- manifests/config.pp | 6 +++--- manifests/init.pp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 82054281..fd6ff590 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -48,9 +48,9 @@ 'Debian': { file { '/etc/default/redis-server': ensure => file, - group => $redis::config_group, - mode => $redis::config_file_mode, - owner => $redis::config_owner, + group => pick($redis::debdefault_group, $redis::config_group), + mode => pick($redis::debdefault_file_mode, $redis::config_file_mode), + owner => pick($redis::debdefault_owner, $redis::config_owner), } } diff --git a/manifests/init.pp b/manifests/init.pp index 312caeb3..076d2577 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -267,6 +267,15 @@ # Adjust filesystem group for $workdir. # @param workdir_owner # Adjust filesystem owner for $workdir. +# @param debdefault_group +# group of /etc/defaults/redis on Debian systems +# if undef, $redis::config_group is taken +# @param debdefault_file_mode +# filemode of /etc/defaults/redis on Debian systems +# if undef, $redis::config_file_mode is taken +# @param debdefault_owner +# owner of /etc/defaults/redis on Debian systems +# if undef, $redis::config_owner is taken # @param zset_max_ziplist_entries # Set max entries for sorted sets. # @param zset_max_ziplist_value @@ -461,6 +470,9 @@ Stdlib::Filemode $workdir_mode = '0750', Optional[String[1]] $workdir_group = undef, Optional[String[1]] $workdir_owner = undef, + Optional[String[1]] $debdefault_group = undef, + Optional[Stdlib::Filemode] $debdefault_file_mode = undef, + Optional[String[1]] $debdefault_owner = undef, Integer[0] $zset_max_ziplist_entries = 128, Integer[0] $zset_max_ziplist_value = 64, Boolean $cluster_enabled = false, From a4fbb8ce02ffae2293e01707356f60b274cc7378 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Mon, 11 Mar 2024 15:49:07 +0100 Subject: [PATCH 3/4] update REFERENCE.md --- REFERENCE.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/REFERENCE.md b/REFERENCE.md index 0902d2e5..3518eed9 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -200,6 +200,11 @@ The following parameters are available in the `redis` class: * [`unixsocketperm`](#-redis--unixsocketperm) * [`workdir`](#-redis--workdir) * [`workdir_mode`](#-redis--workdir_mode) +* [`workdir_group`](#-redis--workdir_group) +* [`workdir_owner`](#-redis--workdir_owner) +* [`debdefault_group`](#-redis--debdefault_group) +* [`debdefault_file_mode`](#-redis--debdefault_file_mode) +* [`debdefault_owner`](#-redis--debdefault_owner) * [`zset_max_ziplist_entries`](#-redis--zset_max_ziplist_entries) * [`zset_max_ziplist_value`](#-redis--zset_max_ziplist_value) * [`cluster_enabled`](#-redis--cluster_enabled) @@ -1161,6 +1166,49 @@ Adjust mode for data directory. Default value: `'0750'` +##### `workdir_group` + +Data type: `Optional[String[1]]` + +Adjust filesystem group for $workdir. + +Default value: `undef` + +##### `workdir_owner` + +Data type: `Optional[String[1]]` + +Adjust filesystem owner for $workdir. + +Default value: `undef` + +##### `debdefault_group` + +Data type: `Optional[String[1]]` + +group of /etc/defaults/redis on Debian systems +if undef, $redis::config_group is taken + +Default value: `undef` + +##### `debdefault_file_mode` + +Data type: `Optional[Stdlib::Filemode]` + +filemode of /etc/defaults/redis on Debian systems +if undef, $redis::config_file_mode is taken + +Default value: `undef` + +##### `debdefault_owner` + +Data type: `Optional[String[1]]` + +owner of /etc/defaults/redis on Debian systems +if undef, $redis::config_owner is taken + +Default value: `undef` + ##### `zset_max_ziplist_entries` Data type: `Integer[0]` From 76ea8ce8a12403e995dcf8b4d1dd42075067d2bf Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Mon, 11 Mar 2024 18:02:03 +0100 Subject: [PATCH 4/4] add spec tests --- spec/classes/redis_spec.rb | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/spec/classes/redis_spec.rb b/spec/classes/redis_spec.rb index 6d72a062..4cc989d4 100644 --- a/spec/classes/redis_spec.rb +++ b/spec/classes/redis_spec.rb @@ -1715,6 +1715,63 @@ class { 'redis': it { is_expected.to contain_systemd__unit_file("#{service_name}.service").with('content' => %r{^TimeoutStartSec=600$}) } it { is_expected.to contain_systemd__unit_file("#{service_name}.service").with('content' => %r{^TimeoutStopSec=300$}) } end + + describe 'with non default ownership' do + let :params do + { + workdir: '/tmp/rediswork', + workdir_group: 'wdirgroup', + workdir_owner: 'wdirowner', + config_group: 'cfggroup', + } + end + + it { + is_expected.to contain_file('/tmp/rediswork').with( + 'ensure' => 'directory', + 'owner' => 'wdirowner', + 'group' => 'wdirgroup', + 'mode' => '0750' + ) + } + + if facts[:os]['family'] == 'Debian' + it { + is_expected.to contain_file('/etc/default/redis-server'). + with( + 'ensure' => 'file', + 'owner' => 'redis', + 'group' => 'cfggroup', + 'mode' => '0640' + ) + } + end + end + + describe 'overwrite debian directory config' do + let :params do + { + config_owner: 'redis', + config_group: 'cfggroup', + config_file_mode: '0333', + debdefault_group: 'dd_group', + debdefault_owner: 'dd_owner', + debdefault_file_mode: '0242', + } + end + + if facts[:os]['family'] == 'Debian' + it { + is_expected.to contain_file('/etc/default/redis-server'). + with( + 'ensure' => 'file', + 'owner' => 'dd_owner', + 'group' => 'dd_group', + 'mode' => '0242' + ) + } + end + end end end end