From 82b790a31fab20d6daa6a8e9320ba0d82ce6149a Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Thu, 16 Jan 2025 10:07:41 -0500 Subject: [PATCH 1/7] add option to define mkfs_options for volumes (#408) --- site/profile/manifests/volumes.pp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/site/profile/manifests/volumes.pp b/site/profile/manifests/volumes.pp index 7c7f186ef..cc11db3a8 100644 --- a/site/profile/manifests/volumes.pp +++ b/site/profile/manifests/volumes.pp @@ -43,6 +43,7 @@ filesystem => pick($values['filesystem'], 'xfs'), require => File["/mnt/${volume_tag}"], quota => pick_default($values['quota'], ''), + mkfs_options => pick_default($values['mkfs_options'], ''), } } } @@ -62,6 +63,7 @@ Boolean $enable_resize, Enum['xfs', 'ext3', 'ext4'] $filesystem, String $quota = '', + String $mkfs_options = '', ) { $regex = Regexp(regsubst($glob, /[?*]/, { '?' => '.', '*' => '.*' })) @@ -104,6 +106,7 @@ ensure => present, volume_group => "${name}_vg", fs_type => $filesystem, + mkfs_options => $mkfs_options, mountpath => "/mnt/${volume_tag}/${volume_name}", mountpath_require => true, options => $options, From a05db955cc9378a009aafbba0a5bf14308adb5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Fortin?= Date: Thu, 16 Jan 2025 10:14:20 -0500 Subject: [PATCH 2/7] Replace pick and pick_default by * => $values in volumes --- site/profile/manifests/volumes.pp | 54 +++++++++++++------------------ 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/site/profile/manifests/volumes.pp b/site/profile/manifests/volumes.pp index cc11db3a8..6226db0fc 100644 --- a/site/profile/manifests/volumes.pp +++ b/site/profile/manifests/volumes.pp @@ -30,20 +30,9 @@ ensure_resource('file', "/mnt/${volume_tag}", { 'ensure' => 'directory' }) $device_map.each | String $key, $values | { profile::volumes::volume { "${volume_tag}-${key}": - volume_name => $key, - volume_tag => $volume_tag, - glob => $values['glob'], - bind_mount => pick($values['bind_mount'], true), - bind_target => pick($values['bind_target'], "/${key}"), - owner => pick($values['owner'], 'root'), - group => pick($values['group'], 'root'), - mode => pick($values['mode'], '0755'), - seltype => pick($values['seltype'], 'home_root_t'), - enable_resize => pick($values['enable_resize'], false), - filesystem => pick($values['filesystem'], 'xfs'), - require => File["/mnt/${volume_tag}"], - quota => pick_default($values['quota'], ''), - mkfs_options => pick_default($values['mkfs_options'], ''), + volume_name => $key, + volume_tag => $volume_tag, + * => $values, } } } @@ -54,18 +43,21 @@ String $volume_name, String $volume_tag, String $glob, - String $owner, - String $mode, - String $group, - String $bind_target, - Boolean $bind_mount, - String $seltype, - Boolean $enable_resize, - Enum['xfs', 'ext3', 'ext4'] $filesystem, - String $quota = '', - String $mkfs_options = '', + Integer $size, + String $owner = 'root', + String $mode = '0755', + String $group = 'root', + Boolean $bind_mount = true, + String $seltype = 'home_root_t', + Boolean $enable_resize = false, + Enum['xfs', 'ext3', 'ext4'] $filesystem = 'xfs', + Optional[String[1]] $quota = undef, + Optional[String[1]] $type = undef, + Optional[String[1]] $mkfs_options = undef, + Optional[String[1]] $bind_target = undef, ) { $regex = Regexp(regsubst($glob, /[?*]/, { '?' => '.', '*' => '.*' })) + $bind_target_ = pick($bind_target, "/${volume_name}") file { "/mnt/${volume_tag}/${volume_name}": ensure => 'directory', @@ -153,27 +145,27 @@ selinux::exec_restorecon { "/mnt/${volume_tag}/${volume_name}": } if $bind_mount { - ensure_resource('file', $bind_target, { 'ensure' => 'directory', 'seltype' => $seltype }) - mount { $bind_target: + ensure_resource('file', $bind_target_, { 'ensure' => 'directory', 'seltype' => $seltype }) + mount { $bind_target_: ensure => mounted, device => "/mnt/${volume_tag}/${volume_name}", fstype => none, options => 'rw,bind', require => [ - File[$bind_target], + File[$bind_target_], Lvm::Logical_volume[$name], ], } } elsif ( - $facts['mountpoints'][$bind_target] != undef and - $facts['mountpoints'][$bind_target]['device'] == $dev_mapper_id + $facts['mountpoints'][$bind_target_] != undef and + $facts['mountpoints'][$bind_target_]['device'] == $dev_mapper_id ) { - mount { $bind_target: + mount { $bind_target_: ensure => absent, } } - if $filesystem == 'xfs' and $quota != '' { + if $quota and $filesystem == 'xfs' { # Save the xfs quota setting to avoid applying at every iteration file { "/etc/xfs_quota/${volume_tag}-${volume_name}": ensure => 'file', From a414967fa0344e679f8a49cd49d1f87eed4fad0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Fortin?= Date: Thu, 16 Jan 2025 10:24:52 -0500 Subject: [PATCH 3/7] Lint --- site/profile/manifests/volumes.pp | 1 - 1 file changed, 1 deletion(-) diff --git a/site/profile/manifests/volumes.pp b/site/profile/manifests/volumes.pp index 6226db0fc..0f20cfa83 100644 --- a/site/profile/manifests/volumes.pp +++ b/site/profile/manifests/volumes.pp @@ -17,7 +17,6 @@ class profile::volumes ( Hash[String, Hash[String, Hash]] $devices, ) { - file { '/etc/xfs_quota': ensure => 'directory', } From 1ca550d84a6d6321221d376c11150678705fc4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Fortin?= Date: Thu, 16 Jan 2025 10:27:32 -0500 Subject: [PATCH 4/7] Move xfs_quota in profiles::volumes::volume --- site/profile/manifests/volumes.pp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/site/profile/manifests/volumes.pp b/site/profile/manifests/volumes.pp index 0f20cfa83..cab5fce91 100644 --- a/site/profile/manifests/volumes.pp +++ b/site/profile/manifests/volumes.pp @@ -17,10 +17,6 @@ class profile::volumes ( Hash[String, Hash[String, Hash]] $devices, ) { - file { '/etc/xfs_quota': - ensure => 'directory', - } - if $devices =~ Hash[String, Hash[String, Hash]] { package { 'lvm2': ensure => installed, @@ -165,11 +161,12 @@ } if $quota and $filesystem == 'xfs' { + ensure_resource('file', '/etc/xfs_quota', { 'ensure' => 'directory' }) # Save the xfs quota setting to avoid applying at every iteration file { "/etc/xfs_quota/${volume_tag}-${volume_name}": ensure => 'file', content => "#FILE TRACKED BY PUPPET DO NOT EDIT MANUALLY\n${quota}", - require => File['/etc/xfs_quota'] + require => File['/etc/xfs_quota'], } exec { "apply-quota-${name}": From ca1be5ecc100a152badc3f62439fce208e14db43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Fortin?= Date: Thu, 16 Jan 2025 10:29:07 -0500 Subject: [PATCH 5/7] Remove useless if in profile::volumes --- site/profile/manifests/volumes.pp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/site/profile/manifests/volumes.pp b/site/profile/manifests/volumes.pp index cab5fce91..b3b8defed 100644 --- a/site/profile/manifests/volumes.pp +++ b/site/profile/manifests/volumes.pp @@ -17,18 +17,16 @@ class profile::volumes ( Hash[String, Hash[String, Hash]] $devices, ) { - if $devices =~ Hash[String, Hash[String, Hash]] { - package { 'lvm2': - ensure => installed, - } - $devices.each | String $volume_tag, $device_map | { - ensure_resource('file', "/mnt/${volume_tag}", { 'ensure' => 'directory' }) - $device_map.each | String $key, $values | { - profile::volumes::volume { "${volume_tag}-${key}": - volume_name => $key, - volume_tag => $volume_tag, - * => $values, - } + package { 'lvm2': + ensure => installed, + } + $devices.each | String $volume_tag, $device_map | { + ensure_resource('file', "/mnt/${volume_tag}", { 'ensure' => 'directory' }) + $device_map.each | String $key, $values | { + profile::volumes::volume { "${volume_tag}-${key}": + volume_name => $key, + volume_tag => $volume_tag, + * => $values, } } } From 868a3631c22c87d90bd797f614f2a2578d09639e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Fortin?= Date: Thu, 16 Jan 2025 10:51:22 -0500 Subject: [PATCH 6/7] Drop ext3 --- site/profile/manifests/volumes.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/profile/manifests/volumes.pp b/site/profile/manifests/volumes.pp index b3b8defed..c2818616e 100644 --- a/site/profile/manifests/volumes.pp +++ b/site/profile/manifests/volumes.pp @@ -43,7 +43,7 @@ Boolean $bind_mount = true, String $seltype = 'home_root_t', Boolean $enable_resize = false, - Enum['xfs', 'ext3', 'ext4'] $filesystem = 'xfs', + Enum['xfs', 'ext4'] $filesystem = 'xfs', Optional[String[1]] $quota = undef, Optional[String[1]] $type = undef, Optional[String[1]] $mkfs_options = undef, From 14bb6819c87b7defe0e549663035d82742bba8ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Fortin?= Date: Thu, 16 Jan 2025 11:18:02 -0500 Subject: [PATCH 7/7] Define minimum for inputs of profile::volumes::volume --- site/profile/manifests/volumes.pp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/site/profile/manifests/volumes.pp b/site/profile/manifests/volumes.pp index c2818616e..d4d514409 100644 --- a/site/profile/manifests/volumes.pp +++ b/site/profile/manifests/volumes.pp @@ -33,21 +33,21 @@ } define profile::volumes::volume ( - String $volume_name, - String $volume_tag, - String $glob, - Integer $size, - String $owner = 'root', - String $mode = '0755', - String $group = 'root', + String[1] $volume_name, + String[1] $volume_tag, + String[1] $glob, + Integer[1] $size, + String[1] $owner = 'root', + String[1] $group = 'root', + String[3,4] $mode = '0755', + String[1] $seltype = 'home_root_t', Boolean $bind_mount = true, - String $seltype = 'home_root_t', Boolean $enable_resize = false, Enum['xfs', 'ext4'] $filesystem = 'xfs', - Optional[String[1]] $quota = undef, + Optional[String[1]] $bind_target = undef, Optional[String[1]] $type = undef, + Optional[String[1]] $quota = undef, Optional[String[1]] $mkfs_options = undef, - Optional[String[1]] $bind_target = undef, ) { $regex = Regexp(regsubst($glob, /[?*]/, { '?' => '.', '*' => '.*' })) $bind_target_ = pick($bind_target, "/${volume_name}")