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 a164ebe
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 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
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:dk@marketing-factory.de>
# * Martin Alfke <tuxmea@gmail.com>
#
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: 18 additions & 11 deletions manifests/server/export.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
# @param v4_export_name
# @param nfsv4_bindmount_enable
#
# @param*create_dir
# Boolean. Create the directory to be exported.
# Defaults to true.
#
# @examples
#
# class { '::nfs':
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
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 a164ebe

Please sign in to comment.