diff --git a/REFERENCE.md b/REFERENCE.md index e3b94b11..b3164fcd 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -796,6 +796,7 @@ The following parameters are available in the `nfs::client::mount` defined type: * [`group`](#-nfs--client--mount--group) * [`mode`](#-nfs--client--mount--mode) * [`mount_root`](#-nfs--client--mount--mount_root) +* [`umask`](#-nfs--client--mount--umask) * [`mount`](#-nfs--client--mount--mount) * [`manage_packages`](#-nfs--client--mount--manage_packages) * [`client_packages`](#-nfs--client--mount--client_packages) @@ -903,6 +904,14 @@ Overwrite mount root if differs from server configuration. Default value: `undef` +##### `umask` + +Data type: `Optional[Stdlib::Filemode]` + +Set umask for mount directory creation. + +Default value: `undef` + ##### `mount` Data type: `String[1]` @@ -945,6 +954,7 @@ The following parameters are available in the `nfs::functions::bindmount` define * [`mount_name`](#-nfs--functions--bindmount--mount_name) * [`ensure`](#-nfs--functions--bindmount--ensure) +* [`umask`](#-nfs--functions--bindmount--umask) ##### `mount_name` @@ -962,6 +972,14 @@ Sets if enabled or not. Default value: `'present'` +##### `umask` + +Data type: `Optional[Stdlib::Filemode]` + +Set umask for mount directory creation. + +Default value: `undef` + ### `nfs::functions::create_export` Manage export creation. @@ -1032,6 +1050,7 @@ Manage directory creation. The following parameters are available in the `nfs::functions::mkdir` defined type: * [`ensure`](#-nfs--functions--mkdir--ensure) +* [`umask`](#-nfs--functions--mkdir--umask) ##### `ensure` @@ -1041,6 +1060,14 @@ Data type: `String[1]` Default value: `'present'` +##### `umask` + +Data type: `Optional[Stdlib::Filemode]` + + + +Default value: `undef` + ### `nfs::functions::nfsv4_bindmount` Manage bindmounts for NFS v4. @@ -1052,6 +1079,7 @@ The following parameters are available in the `nfs::functions::nfsv4_bindmount` * [`v4_export_name`](#-nfs--functions--nfsv4_bindmount--v4_export_name) * [`bind`](#-nfs--functions--nfsv4_bindmount--bind) * [`ensure`](#-nfs--functions--nfsv4_bindmount--ensure) +* [`umask`](#-nfs--functions--nfsv4_bindmount--umask) ##### `v4_export_name` @@ -1073,6 +1101,14 @@ Sets if mounted or not. Default value: `'mounted'` +##### `umask` + +Data type: `Optional[Stdlib::Filemode]` + +Set umask for mount directory creation. + +Default value: `undef` + ### `nfs::server::export` Manage all exported resources on a NFS server. diff --git a/manifests/client/mount.pp b/manifests/client/mount.pp index f74fee9c..37ef3b88 100644 --- a/manifests/client/mount.pp +++ b/manifests/client/mount.pp @@ -42,6 +42,9 @@ # @param mount_root # Overwrite mount root if differs from server configuration. # +# @param umask +# Set umask for mount directory creation. +# # @param mount # @param manage_packages # @param client_packages @@ -83,6 +86,7 @@ Optional[String[1]] $mount_root = undef, Boolean $manage_packages = $nfs::manage_packages, Optional[Variant[String[1], Array[String[1]]]] $client_packages = $nfs::effective_client_packages, + Optional[Stdlib::Filemode] $umask = undef, ) { if $manage_packages and $client_packages != undef { $mount_require = [Nfs::Functions::Mkdir[$mount], Package[$client_packages]] @@ -105,6 +109,7 @@ nfs::functions::mkdir { $mount: ensure => $ensure, + umask => $umask, } mount { "shared ${sharename} by ${server} on ${mount}": @@ -133,6 +138,7 @@ nfs::functions::mkdir { $mount: ensure => $ensure, + umask => $umask, } mount { "shared ${sharename} by ${server} on ${mount}": ensure => $ensure, diff --git a/manifests/functions/bindmount.pp b/manifests/functions/bindmount.pp index 8b2aa2a7..882abf4c 100644 --- a/manifests/functions/bindmount.pp +++ b/manifests/functions/bindmount.pp @@ -6,6 +6,9 @@ # @param ensure # Sets if enabled or not. # +# @param umask +# Set umask for mount directory creation. +# # @author # * Daniel Klockenkaemper # * Martin Alfke @@ -13,9 +16,11 @@ define nfs::functions::bindmount ( Optional[String[1]] $mount_name = undef, String[1] $ensure = 'present', + Optional[Stdlib::Filemode] $umask = undef, ) { nfs::functions::mkdir { $mount_name: ensure => $ensure, + umask => $umask, } mount { $mount_name: ensure => $ensure, diff --git a/manifests/functions/mkdir.pp b/manifests/functions/mkdir.pp index b3565b32..60460715 100644 --- a/manifests/functions/mkdir.pp +++ b/manifests/functions/mkdir.pp @@ -1,6 +1,7 @@ # @summary Manage directory creation. # # @param ensure +# @param umask # # @author # * Daniel Klockenkaemper @@ -8,11 +9,17 @@ # define nfs::functions::mkdir ( String[1] $ensure = 'present', + Optional[Stdlib::Filemode] $umask = undef, ) { if $ensure != 'absent' { + $_command = $umask ? { + undef => "mkdir -p ${name}", + default => "bash -c 'umask ${umask} && mkdir -p ${name}'", + } + exec { "mkdir_recurse_${name}": path => ['/bin', '/usr/bin'], - command => "mkdir -p ${name}", + command => $_command, unless => "test -d ${name}", } } diff --git a/manifests/functions/nfsv4_bindmount.pp b/manifests/functions/nfsv4_bindmount.pp index 1512637a..bd0fed59 100644 --- a/manifests/functions/nfsv4_bindmount.pp +++ b/manifests/functions/nfsv4_bindmount.pp @@ -9,6 +9,9 @@ # @param ensure # Sets if mounted or not. # +# @param umask +# Set umask for mount directory creation. +# # @author # * Daniel Klockenkaemper # * Martin Alfke @@ -17,11 +20,13 @@ String[1] $v4_export_name, String[1] $bind, String[1] $ensure = 'mounted', + Optional[Stdlib::Filemode] $umask = undef, ) { $normalize_export_root = regsubst($nfs::server::nfs_v4_export_root, '/$', '') $expdir = "${normalize_export_root}/${v4_export_name}" nfs::functions::mkdir { $expdir: ensure => $ensure, + umask => $umask, } mount { $expdir: ensure => $ensure, diff --git a/spec/defines/client_mount_spec.rb b/spec/defines/client_mount_spec.rb index 40fb560a..3417a8b2 100644 --- a/spec/defines/client_mount_spec.rb +++ b/spec/defines/client_mount_spec.rb @@ -32,6 +32,8 @@ it { is_expected.to contain_nfs__functions__mkdir('/srv/test') } + it { is_expected.to contain_exec('mkdir_recurse_/srv/test').with(command: 'mkdir -p /srv/test') } + it do is_expected.to contain_mount('shared /srv/test by 1.2.3.4 on /srv/test').that_requires( [ @@ -131,6 +133,26 @@ ) end end + + context 'when nfs_v4 => false, non-default umask' do + let(:title) { '/srv/test' } + + let(:pre_condition) { 'class { "nfs": client_enabled => true }' } + + let(:params) { { server: '1.2.3.4', umask: '0022' } } + + it { is_expected.to contain_nfs__functions__mkdir('/srv/test') } + + it { is_expected.to contain_exec('mkdir_recurse_/srv/test').with(command: "bash -c 'umask 0022 && mkdir -p /srv/test'") } + + it do + is_expected.to contain_mount('shared /srv/test by 1.2.3.4 on /srv/test').that_requires( + [ + 'Nfs::Functions::Mkdir[/srv/test]', + ] + client_packages, + ) + end + end end end end