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/manifests/functions/create_export.pp b/manifests/functions/create_export.pp index b610135..24d6ac3 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..8396545 100644 --- a/manifests/server/export.pp +++ b/manifests/server/export.pp @@ -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': @@ -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"}