Skip to content

Commit

Permalink
Add the option to create the exported directory on the NFS server or …
Browse files Browse the repository at this point in the history
…not.
  • Loading branch information
bschonec committed Jun 10, 2024
1 parent 8409ddf commit 1a9fa3c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
25 changes: 24 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

* [`nfs::client::mount`](#nfs--client--mount): Function: nfs::client::mount This Function exists to 1. manage all mounts on a nfs client Parameters param nfs_v4 Boolean. When set to
* [`nfs::functions::bindmount`](#nfs--functions--bindmount): Function: nfs::functions::bindmount This Function exists to 1. manage bindmounts * Daniel Klockenkaemper <mailto:[email protected]>
* [`nfs::functions::create_export`](#nfs--functions--create_export): Function: nfs::functions::create_export This Function exists to 1. manage export creation * Daniel Klockenkaemper <mailto:dk@marketing-fac
* [`nfs::functions::create_export`](#nfs--functions--create_export): Function: nfs::functions::create_export This Function exists to 1. manage export creation @param*create_dir Boolean. Create the directo
* [`nfs::functions::mkdir`](#nfs--functions--mkdir): Function: nfs::functions::mkdir This Function exists to 1. manage dir creation * Daniel Klockenkaemper <mailto:[email protected]> *
* [`nfs::functions::nfsv4_bindmount`](#nfs--functions--nfsv4_bindmount): Function: nfs::functions::nfsv4_bindmount This Function exists to 1. manage bindmounts for nfs4 * Daniel Klockenkaemper <mailto:dk@marketi
* [`nfs::server::export`](#nfs--server--export): Function: nfs::server::export This Function exists to 1. manage all exported resources on a nfs server Parameters class { '::nfs': serv
Expand Down Expand Up @@ -1097,6 +1097,10 @@ Function: nfs::functions::create_export
This Function exists to
1. manage export creation

@param*create_dir
Boolean. Create the directory to be exported.
Defaults to true.

* Daniel Klockenkaemper <mailto:[email protected]>
* Martin Alfke <[email protected]>

Expand All @@ -1109,6 +1113,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)

##### <a name="-nfs--functions--create_export--clients"></a>`clients`

Expand Down Expand Up @@ -1148,6 +1153,14 @@ String. Sets the permissions of the exported directory.

Default value: `undef`

##### <a name="-nfs--functions--create_export--create_dir"></a>`create_dir`

Data type: `Boolean`



Default value: `true`

### <a name="nfs--functions--mkdir"></a>`nfs::functions::mkdir`

Function: nfs::functions::mkdir
Expand Down Expand Up @@ -1260,6 +1273,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)

##### <a name="-nfs--server--export--clients"></a>`clients`

Expand Down Expand Up @@ -1402,3 +1416,12 @@ Data type: `Boolean`

Default value: `$nfs::nfsv4_bindmount_enable`

##### <a name="-nfs--server--export--create_dir"></a>`create_dir`

Data type: `Boolean`

Boolean. Create the directory to be exported.
Defaults to true.

Default value: `true`

20 changes: 14 additions & 6 deletions manifests/functions/create_export.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
# @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 <mailto:[email protected]>
# * Martin Alfke <[email protected]>
#
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,
Expand All @@ -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,
}
}
}
}
Expand Down
29 changes: 17 additions & 12 deletions manifests/server/export.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
# @param v4_export_name
# @param nfsv4_bindmount_enable
#
# @examples
# @param create_dir
# Boolean. Create the directory to be exported.
# Defaults to true.
#
# class { '::nfs':
# server_enabled => true,
Expand Down Expand Up @@ -101,6 +103,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 {
Expand All @@ -120,12 +123,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 {
Expand Down Expand Up @@ -154,11 +158,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 {
Expand Down
1 change: 1 addition & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit 1a9fa3c

Please sign in to comment.