Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for create nfs exported directory #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,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',
ensure => 'present',
nfstag => 'media',
clients => '10.0.0.0/24(rw,insecure,async,no_root_squash) localhost(rw)',
clients => '10.0.0.0/24(rw,insecure,async,no_root_squash) localhost(rw)',
manage_dir => false,
}
}

Expand Down
37 changes: 31 additions & 6 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,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)
* [`manage_directory`](#-nfs--functions--create_export--manage_directory)

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

Expand Down Expand Up @@ -1051,6 +1052,14 @@ Sets the permissions of the exported directory.

Default value: `undef`

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

Data type: `Boolean`

Whether or not to manage the directory to be exported.

Default value: `true`

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

Manage directory creation.
Expand Down Expand Up @@ -1103,7 +1112,19 @@ Default value: `'mounted'`

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

Manage all exported resources on a NFS server.
nfs::server::export { '/srv/nfs_exported/directory':
clients => '1.2.3.4/24(rw,insecure,no_subtree_check,async,no_root_squash) 5.6.7.8/24(ro)',
share => 'share_name_on_nfs_server',
}

Links

* {Puppet Docs: Using Parameterized Classes}[http://j.mp/nVpyWY]

nfs::server::export { '/srv/nfs_exported/directory':
clients => '1.2.3.4/24(rw,insecure,no_subtree_check,async,no_root_squash) 5.6.7.8/24(ro)',
share => 'share_name_on_nfs_server',
}

#### Examples

Expand All @@ -1116,11 +1137,6 @@ class { '::nfs':
nfs_v4_export_root => '/share',
nfs_v4_export_root_clients => '1.2.3.4/24(rw,fsid=root,insecure,no_subtree_check,async,no_root_squash)',
}

nfs::server::export { '/srv/nfs_exported/directory':
clients => '1.2.3.4/24(rw,insecure,no_subtree_check,async,no_root_squash) 5.6.7.8/24(ro)',
share => 'share_name_on_nfs_server',
}
```

#### Parameters
Expand All @@ -1144,6 +1160,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)
* [`manage_directory`](#-nfs--server--export--manage_directory)

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

Expand Down Expand Up @@ -1282,3 +1299,11 @@ Data type: `Boolean`

Default value: `$nfs::nfsv4_bindmount_enable`

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

Data type: `Boolean`

Whether or not to manage the directory to be exported.

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 @@ -15,13 +15,17 @@
# @param mode
# Sets the permissions of the exported directory.
#
# @param manage_directory
# Whether or not to manage the directory to be exported.
#
# @author
# * Daniel Klockenkaemper <[email protected]>
# * Martin Alfke <[email protected]>
#
define nfs::functions::create_export (
Variant[String[1], Array[String[1]]] $clients,
String[1] $ensure = 'present',
Boolean $manage_directory = true,
Optional[String[1]] $owner = undef,
Optional[String[1]] $group = undef,
Optional[String[1]] $mode = undef,
Expand All @@ -34,13 +38,17 @@
content => $line,
}

# Create the directory path only if a File resource isn't
# defined previously AND the $manage_directory boolean is true.
unless defined(File[$name]) {
file { $name:
ensure => directory,
owner => $owner,
group => $group,
mode => $mode,
selinux_ignore_defaults => true,
if $manage_directory {
file { $name:
ensure => directory,
owner => $owner,
group => $group,
mode => $mode,
selinux_ignore_defaults => true,
}
}
}
}
Expand Down
37 changes: 26 additions & 11 deletions manifests/server/export.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
# @param v4_export_name
# @param nfsv4_bindmount_enable
#
# @param manage_directory
# Whether or not to manage the directory to be exported.
#
# @example
# class { '::nfs':
# server_enabled => true,
Expand All @@ -55,6 +58,15 @@
# nfs_v4_export_root_clients => '1.2.3.4/24(rw,fsid=root,insecure,no_subtree_check,async,no_root_squash)',
# }
#
# nfs::server::export { '/srv/nfs_exported/directory':
# clients => '1.2.3.4/24(rw,insecure,no_subtree_check,async,no_root_squash) 5.6.7.8/24(ro)',
# share => 'share_name_on_nfs_server',
# }
#
# Links
#
# * {Puppet Docs: Using Parameterized Classes}[http://j.mp/nVpyWY]
#
# nfs::server::export { '/srv/nfs_exported/directory':
# clients => '1.2.3.4/24(rw,insecure,no_subtree_check,async,no_root_squash) 5.6.7.8/24(ro)',
# share => 'share_name_on_nfs_server',
Expand Down Expand Up @@ -84,6 +96,7 @@
Optional[String[1]] $mode = undef,
String[1] $server = $facts['clientcert'],
Boolean $nfsv4_bindmount_enable = $nfs::nfsv4_bindmount_enable,
Boolean $manage_directory = true,
) {
if $nfs::server::nfs_v4 {
if $nfsv4_bindmount_enable {
Expand All @@ -103,12 +116,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,
manage_directory => $manage_directory,
owner => $owner,
group => $group,
mode => $mode,
require => $create_export_require,
}

if $mount != undef {
Expand Down Expand Up @@ -137,11 +151,12 @@
}

nfs::functions::create_export { $v3_export_name:
ensure => $ensure,
clients => $clients,
owner => $owner,
group => $group,
mode => $mode,
ensure => $ensure,
clients => $clients,
manage_directory => $manage_directory,
owner => $owner,
group => $group,
mode => $mode,
}

if $nfs::storeconfigs_enabled {
Expand Down
14 changes: 12 additions & 2 deletions spec/defines/server_export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@

let(:params) { { clients: '1.2.3.4(rw)' } }

it { is_expected.to contain_nfs__functions__create_export('/srv/test').with('ensure' => 'mounted', 'clients' => '1.2.3.4(rw)') }
it do
is_expected.to contain_nfs__functions__create_export('/srv/test').with(
'ensure' => 'mounted',
'clients' => '1.2.3.4(rw)',
'manage_directory' => true
)
end

it { is_expected.to contain_file('/srv/test').with('ensure' => 'directory') }

it do
expect(exported_resources).to contain_nfs__client__mount('/srv/test')
Expand Down Expand Up @@ -70,10 +78,12 @@

let(:pre_condition) { 'class {"nfs": server_enabled => true, nfs_v4 => false, storeconfigs_enabled => false}' }

let(:params) { { clients: '1.2.3.4(rw)' } }
let(:params) { { clients: '1.2.3.4(rw)', manage_directory: false } }

it { is_expected.to contain_nfs__functions__create_export('/srv/test').with('ensure' => 'mounted', 'clients' => '1.2.3.4(rw)') }

it { is_expected.not_to contain_file('/srv/test') }

it { expect(exported_resources).not_to contain_nfs__client__mount('/srv/test') }
end

Expand Down
Loading