Skip to content

Commit ac2b4b8

Browse files
author
Josh Sinfield
committed
Issue echocat#30 Add ability to set owner,group,perms on server::export
When using the nfs::server::export resource it creates a bindmount resource, which in turn creates a nfs::mkdir resource. Adding these parameters and passing them through provides the ability to set owner, group and mode metaparams on the file resource within nfs::mkdir from a server::export resource.
1 parent 39f2260 commit ac2b4b8

File tree

3 files changed

+109
-93
lines changed

3 files changed

+109
-93
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ and on individual nodes.
170170
}
171171
}
172172
```
173+
Set ownership and permissions on the folder being exported
174+
175+
```puppet
176+
node server {
177+
nfs::server::export{ '/data_folder':
178+
ensure => 'mounted',
179+
clients => '10.0.0.0/24(rw,insecure,no_subtree_check,async,no_root_squash) localhost(rw)',
180+
owner => 'root',
181+
group => 'root',
182+
perms => '0755',
183+
}
184+
}
185+
```
173186

174187
By default, mounts are mounted in the same folder on the clients as
175188
they were exported from on the server

manifests/server/export.pp

+71-72
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,71 @@
1-
define nfs::server::export (
2-
$v3_export_name = $name,
3-
# Grab the final directory name in the given path and make it our default nfsv4 export name.
4-
$v4_export_name = regsubst($name, '.*/([^/]+)/?$', '\1' ),
5-
$clients = 'localhost(ro)',
6-
$bind = 'rbind',
7-
# globals for this share
8-
# propogated to storeconfigs
9-
$ensure = 'mounted',
10-
$mount = undef,
11-
$remounts = false,
12-
$atboot = false,
13-
$options = '_netdev',
14-
$bindmount = undef,
15-
$nfstag = undef,
16-
$server = $::clientcert
17-
) {
18-
19-
20-
if $nfs::server::nfs_v4 {
21-
22-
nfs::server::export::nfs_v4::bindmount { $name:
23-
ensure => $ensure,
24-
v4_export_name => $v4_export_name,
25-
bind => $bind,
26-
}
27-
28-
nfs::server::export::configure{
29-
"${nfs::server::nfs_v4_export_root}/${v4_export_name}":
30-
ensure => $ensure,
31-
clients => $clients,
32-
require => Nfs::Server::Export::Nfs_v4::Bindmount[$name]
33-
}
34-
35-
@@nfs::client::mount {"shared ${v4_export_name} by ${::clientcert}":
36-
ensure => $ensure,
37-
mount => $mount,
38-
remounts => $remounts,
39-
atboot => $atboot,
40-
options => $options,
41-
bindmount => $bindmount,
42-
nfstag => $nfstag,
43-
share => $v4_export_name,
44-
server => $server,
45-
}
46-
47-
} else {
48-
49-
nfs::server::export::configure{
50-
$v3_export_name:
51-
ensure => $ensure,
52-
clients => $clients,
53-
}
54-
55-
if $mount == undef {
56-
$_mount = $v3_export_name
57-
} else {
58-
$_mount = $mount
59-
}
60-
61-
@@nfs::client::mount {"shared ${v3_export_name} by ${::clientcert}":
62-
ensure => $ensure,
63-
mount => $_mount,
64-
remounts => $remounts,
65-
atboot => $atboot,
66-
options => $options,
67-
nfstag => $nfstag,
68-
share => $v3_export_name,
69-
server => $server,
70-
}
71-
}
72-
}
1+
define nfs::server::export (
2+
$v3_export_name = $name,
3+
# Grab the final directory name in the given path and make it our default nfsv4 export name.
4+
$v4_export_name = regsubst($name, '.*/([^/]+)/?$', '\1'),
5+
$clients = 'localhost(ro)',
6+
$bind = 'rbind',
7+
$owner = 'root',
8+
$group = 'root',
9+
$perms = '0755',
10+
# globals for this share
11+
# propogated to storeconfigs
12+
$ensure = 'mounted',
13+
$mount = undef,
14+
$remounts = false,
15+
$atboot = false,
16+
$options = '_netdev',
17+
$bindmount = undef,
18+
$nfstag = undef,
19+
$server = $::clientcert) {
20+
if $nfs::server::nfs_v4 {
21+
nfs::server::export::nfs_v4::bindmount { $name:
22+
ensure => $ensure,
23+
v4_export_name => $v4_export_name,
24+
bind => $bind,
25+
owner => $owner,
26+
group => $group,
27+
perms => $perms,
28+
}
29+
30+
nfs::server::export::configure { "${nfs::server::nfs_v4_export_root}/${v4_export_name}":
31+
ensure => $ensure,
32+
clients => $clients,
33+
require => Nfs::Server::Export::Nfs_v4::Bindmount[$name]
34+
}
35+
36+
@@nfs::client::mount { "shared ${v4_export_name} by ${::clientcert}":
37+
ensure => $ensure,
38+
mount => $mount,
39+
remounts => $remounts,
40+
atboot => $atboot,
41+
options => $options,
42+
bindmount => $bindmount,
43+
nfstag => $nfstag,
44+
share => $v4_export_name,
45+
server => $server,
46+
}
47+
48+
} else {
49+
nfs::server::export::configure { $v3_export_name:
50+
ensure => $ensure,
51+
clients => $clients,
52+
}
53+
54+
if $mount == undef {
55+
$_mount = $v3_export_name
56+
} else {
57+
$_mount = $mount
58+
}
59+
60+
@@nfs::client::mount { "shared ${v3_export_name} by ${::clientcert}":
61+
ensure => $ensure,
62+
mount => $_mount,
63+
remounts => $remounts,
64+
atboot => $atboot,
65+
options => $options,
66+
nfstag => $nfstag,
67+
share => $v3_export_name,
68+
server => $server,
69+
}
70+
}
71+
}
+25-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
define nfs::server::export::nfs_v4::bindmount (
2-
$v4_export_name,
3-
$bind,
4-
$ensure = 'mounted',
5-
) {
6-
7-
$expdir = "${nfs::server::nfs_v4_export_root}/${v4_export_name}"
8-
9-
nfs::mkdir{ $expdir: }
10-
11-
mount {
12-
$expdir:
13-
ensure => $ensure,
14-
device => $name,
15-
atboot => true,
16-
fstype => 'none',
17-
options => $bind,
18-
require => Nfs::Mkdir[$expdir],
19-
}
20-
21-
}
1+
define nfs::server::export::nfs_v4::bindmount (
2+
$v4_export_name,
3+
$bind,
4+
$ensure = 'mounted',
5+
$owner = 'root',
6+
$group = 'root',
7+
$perms = '0755') {
8+
$expdir = "${nfs::server::nfs_v4_export_root}/${v4_export_name}"
9+
10+
nfs::mkdir { $expdir:
11+
owner => $owner,
12+
group => $group,
13+
perm => $perms
14+
}
15+
16+
mount { $expdir:
17+
ensure => $ensure,
18+
device => $name,
19+
atboot => true,
20+
fstype => 'none',
21+
options => $bind,
22+
require => Nfs::Mkdir[$expdir],
23+
}
24+
25+
}

0 commit comments

Comments
 (0)