From 6e9b743d3c051ceee3a7e88d70178920d260fbe2 Mon Sep 17 00:00:00 2001 From: Brian Schonecker Date: Wed, 12 Jun 2024 13:21:10 -0400 Subject: [PATCH] Add the option to create the exported directory on the NFS server or not. --- .fixtures.yml | 1 + README.md | 2 ++ REFERENCE.md | 20 ++++++++++++++++++ manifests/functions/create_export.pp | 20 ++++++++++++------ manifests/server/export.pp | 31 +++++++++++++++++----------- metadata.json | 1 + 6 files changed, 57 insertions(+), 18 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index a18692c..93a36da 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -7,5 +7,6 @@ fixtures: augeas_core: "https://github.com/puppetlabs/puppetlabs-augeas_core.git" mount_core: "https://github.com/puppetlabs/puppetlabs-mount_core.git" transition: "https://github.com/puppetlabs/puppetlabs-transition.git" + filepath: "https://github.com/EdgeJ/puppet-filepath.git" symlinks: "nfs": "#{source_dir}" diff --git a/README.md b/README.md index be9d937..e5e7bc8 100644 --- a/README.md +++ b/README.md @@ -152,10 +152,12 @@ This will mount /data on client in /share/data. } # ensure is passed to mount, which will make the client not mount it # the directory automatically, just add it to fstab + # The directory on the NFS server is not created automatically. nfs::server::export { '/media_library': ensure => 'present', nfstag => 'media', clients => '10.0.0.0/24(rw,insecure,async,no_root_squash) localhost(rw)', + create_dir => false, } } diff --git a/REFERENCE.md b/REFERENCE.md index ad547db..35ba4dd 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1109,6 +1109,7 @@ The following parameters are available in the `nfs::functions::create_export` de * [`owner`](#-nfs--functions--create_export--owner) * [`group`](#-nfs--functions--create_export--group) * [`mode`](#-nfs--functions--create_export--mode) +* [`create_dir`](#-nfs--functions--create_export--create_dir) ##### `clients` @@ -1148,6 +1149,15 @@ String. Sets the permissions of the exported directory. Default value: `undef` +##### `create_dir` + +Data type: `Boolean` + +Boolean. Create the directory to be exported. +Defaults to true. + +Default value: `true` + ### `nfs::functions::mkdir` Function: nfs::functions::mkdir @@ -1260,6 +1270,7 @@ The following parameters are available in the `nfs::server::export` defined type * [`v3_export_name`](#-nfs--server--export--v3_export_name) * [`v4_export_name`](#-nfs--server--export--v4_export_name) * [`nfsv4_bindmount_enable`](#-nfs--server--export--nfsv4_bindmount_enable) +* [`create_dir`](#-nfs--server--export--create_dir) ##### `clients` @@ -1402,3 +1413,12 @@ Data type: `Boolean` Default value: `$nfs::nfsv4_bindmount_enable` +##### `create_dir` + +Data type: `Boolean` + +Boolean. Create the directory to be exported. +Defaults to true. + +Default value: `true` + diff --git a/manifests/functions/create_export.pp b/manifests/functions/create_export.pp index b610135..94f2bc0 100644 --- a/manifests/functions/create_export.pp +++ b/manifests/functions/create_export.pp @@ -19,6 +19,10 @@ # @param mode # String. Sets the permissions of the exported directory. # +# @param create_dir +# Boolean. Create the directory to be exported. +# Defaults to true. +# # @author # * Daniel Klockenkaemper # * Martin Alfke @@ -26,6 +30,7 @@ define nfs::functions::create_export ( Variant[String[1], Array[String[1]]] $clients, String[1] $ensure = 'present', + Boolean $create_dir = true, Optional[String[1]] $owner = undef, Optional[String[1]] $group = undef, Optional[String[1]] $mode = undef, @@ -38,13 +43,16 @@ content => $line, } + # Create the directory path only if a File resource isn't + # # defined previously AND the $create_dir boolean is true. unless defined(File[$name]) { - file { $name: - ensure => directory, - owner => $owner, - group => $group, - mode => $mode, - selinux_ignore_defaults => true, + if $create_dir { + filepath { $name: + ensure => present, + owner => $owner, + group => $group, + mode => $mode, + } } } } diff --git a/manifests/server/export.pp b/manifests/server/export.pp index 3b5a26b..f15312b 100644 --- a/manifests/server/export.pp +++ b/manifests/server/export.pp @@ -57,7 +57,11 @@ # @param v4_export_name # @param nfsv4_bindmount_enable # -# @examples +# @param create_dir +# Boolean. Create the directory to be exported. +# Defaults to true. +# +# @example # # class { '::nfs': # server_enabled => true, @@ -101,6 +105,7 @@ Optional[String[1]] $mode = undef, String[1] $server = $facts['clientcert'], Boolean $nfsv4_bindmount_enable = $nfs::nfsv4_bindmount_enable, + Boolean $create_dir = true, ) { if $nfs::server::nfs_v4 { if $nfsv4_bindmount_enable { @@ -120,12 +125,13 @@ } nfs::functions::create_export { $export_title: - ensure => $ensure, - clients => $clients, - owner => $owner, - group => $group, - mode => $mode, - require => $create_export_require, + ensure => $ensure, + clients => $clients, + create_dir => $create_dir, + owner => $owner, + group => $group, + mode => $mode, + require => $create_export_require, } if $mount != undef { @@ -154,11 +160,12 @@ } nfs::functions::create_export { $v3_export_name: - ensure => $ensure, - clients => $clients, - owner => $owner, - group => $group, - mode => $mode, + ensure => $ensure, + clients => $clients, + create_dir => $create_dir, + owner => $owner, + group => $group, + mode => $mode, } if $nfs::storeconfigs_enabled { diff --git a/metadata.json b/metadata.json index a483a44..d3269c2 100644 --- a/metadata.json +++ b/metadata.json @@ -12,6 +12,7 @@ {"name":"puppetlabs/concat","version_requirement":">= 1.1.2 < 10.0.0"}, {"name":"puppetlabs/transition","version_requirement":">= 0.1.0 < 3.0.0"}, {"name":"puppet/augeasproviders_core","version_requirement":">= 2.1.5 < 5.0.0"}, + {"name":"edgej-filepath","version_requirement":">= 1.0.0"}, {"name":"puppet/augeasproviders_shellvar","version_requirement":">= 1.2.0 <= 7.0.0"}, {"name":"puppetlabs/augeas_core","version_requirement":">= 1.2.0 <= 2.0.0"}, {"name":"puppetlabs/mount_core","version_requirement":">= 1.2.0 <= 2.0.0"}