NFS mount problem

953 views
Skip to first unread message

Forrie

unread,
Mar 3, 2011, 6:11:40 PM3/3/11
to Puppet Users
I'm trying to get a simple NFS mount to work with Puppet, using this:

[ init.pp ]

class myclass {

mount { "/home/directory":
device => "server.domain.com:/exportdir/directory",
fstype => "nfs",
ensure => "mounted",
options => "tcp,intr,hard,rw,bg,rsize=32768,wsize=32768",
atboot => "true,
}

}

I get these errors:

Mar 3 18:08:04 test-fms puppet-agent[20989]: Could not retrieve
catalog from remote server: wrong header line format
Mar 3 18:08:04 test-fms puppet-agent[20989]: Using cached catalog
Mar 3 18:08:04 test-fms puppet-agent[20989]: Could not retrieve
catalog; skipping run

I've tried variations using "mount { "directory":" and including the
"path" directive in there, and still no luck.

The server has properly exported the directory via NFS, the
permissions are correct; similarly, the local mount point directory
exists.

What's wrong?



Thanks.

Ben Hughes

unread,
Mar 3, 2011, 7:17:54 PM3/3/11
to puppet...@googlegroups.com
On Thu, Mar 03, 2011 at 03:11:40PM -0800, Forrie wrote:

> I'm trying to get a simple NFS mount to work with Puppet, using this:

[snip]

> atboot => "true,

Missing a "
(:

--
Ben Hughes || http://www.puppetlabs.com/

Forrie

unread,
Mar 3, 2011, 8:49:58 PM3/3/11
to Puppet Users
I caught that, thank you -- I've wiped my glasses thoroughly ;-)

One other issue I'm running into is I would like the client to
*create* (mkdir) the mountpoint with the correct permissions if it
doesn't exist. I don't see a way that can be done within the mount
{} construct... is there a clever way I can do this for a multiple of
directories. Maybe from an array.

Thank you.

Forrie

unread,
Mar 3, 2011, 8:54:17 PM3/3/11
to Puppet Users
It looks like you can't change the definition of "ensure => mounted"
to "ensure => absent" and have it automatically remove the managed
resource (mount point). We have a series of directories that are
used for all three terms, after we're done, we don't need the NFS
mounts or directories present.

Thx.

Ben Hughes

unread,
Mar 3, 2011, 8:55:26 PM3/3/11
to puppet...@googlegroups.com
On Thu, Mar 03, 2011 at 05:49:58PM -0800, Forrie wrote:

> I caught that, thank you -- I've wiped my glasses thoroughly ;-)

(:

> One other issue I'm running into is I would like the client to
> *create* (mkdir) the mountpoint with the correct permissions if it
> doesn't exist. I don't see a way that can be done within the mount
> {} construct...

No, mount has no way to create the directories, it's purely an
interface to the mount command.

> is there a clever way I can do this for a multiple of
> directories. Maybe from an array.

Do it automatically? Rather than just using a file{...} call?

file{ [ "/srv/mount1" , "/srv/mount2" ]: ... }
and so forth.

Forrie

unread,
Mar 3, 2011, 10:38:28 PM3/3/11
to Puppet Users
I'm trying to figure out how to manage the NFS mounts, then 'unmanage'
them when we're done -- ie: remove the NFS mount (ensure => absent)
and make sure the mount point on the client is removed.

I thought for the mount{} portion of this and loop over it. But it's
not a big deal, I don't mind editing them manually for now.

So are you saying for the "absent" items, we'll need to include a
file{} directive to remove the mount point, too?


Thanks again.

Ben Hughes

unread,
Mar 3, 2011, 10:46:53 PM3/3/11
to puppet...@googlegroups.com
On Thu, Mar 03, 2011 at 07:38:28PM -0800, Forrie wrote:

> So are you saying for the "absent" items, we'll need to include a
> file{} directive to remove the mount point, too?

The mount handler won't go around deleting directories for you,
thankfully. (:

Do you create the mount point before you mount it, a la?

file{ "/srv/fraser":
ensure => directory,
owner => "root",
mode => 0755,
}

mount{ "/srv/fraser":
device => "server:/path/fraser",


fstype => "nfs",
ensure => "mounted",

options => "defaults",
atboot => true,
require => File[ "/srv/fraser" ]
}

You could probably make a define to wrap around both to ensure => absent
the directory after you ensure => absent the mount point?

Forrie

unread,
Mar 4, 2011, 10:42:22 AM3/4/11
to Puppet Users
I manually created the mount points and incorrectly assumed the mount
process would automatically create the point if it didn't exist.

Once a managed mount point is no longer needed, we want the NFS mount
its directory removed from the client -- if we need them again, I can
just keep them commented out in the code.

Can you explain the wrap you were talking about?


Thanks!

Stefan Schlesinger

unread,
Mar 4, 2011, 11:15:05 AM3/4/11
to puppet...@googlegroups.com
Just take a look at example42's nfs module, it should already provide the functionallity you are looking for.

Regards, Stefan.

> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
>

Forrie

unread,
Mar 4, 2011, 11:34:32 AM3/4/11
to Puppet Users

Stefan Schulte

unread,
Mar 4, 2011, 12:01:26 PM3/4/11
to Puppet Users
On Thu, Mar 03, 2011 at 07:38:28PM -0800, Forrie wrote:
> I'm trying to figure out how to manage the NFS mounts, then 'unmanage'
> them when we're done -- ie: remove the NFS mount (ensure => absent)
> and make sure the mount point on the client is removed.
>
> I thought for the mount{} portion of this and loop over it. But it's
> not a big deal, I don't mind editing them manually for now.
>
> So are you saying for the "absent" items, we'll need to include a
> file{} directive to remove the mount point, too?
>
yes. And remember to put a require in there because you don't want to
purge the mountpoint when umounting failed. Can turn out pretty bad
for NFS mounts you need elsewhere ;-)


# Creation
file { '/mnt/foo': ensure => directory }
mount { '/mnt/foo':
device => ...,
ensure => mounted,
require => File['/mnt/foo'],
}

# Delete (i think force is needed here)
file { '/mnt/foo': ensure => absent, force => true}
mount { '/mnt/foo':
ensure => absent,
before => File['/mnt/foo'],
}

-Stefan

Ben Hughes

unread,
Mar 6, 2011, 7:08:16 PM3/6/11
to puppet...@googlegroups.com
On Fri, Mar 04, 2011 at 07:42:22AM -0800, Forrie wrote:

> I manually created the mount points and incorrectly assumed the mount
> process would automatically create the point if it didn't exist.

Afraid it doesn't, they have to exist before hand.

> Can you explain the wrap you were talking about?

Either make a module for nfs and have the function create the mountpoints
on "ensure" and rmdir them after "absent", would be one way.

Or use run stages and have a "post" stage unmount them and tidy up the
directories you no longer require.

Forrie

unread,
Mar 16, 2011, 5:22:37 PM3/16/11
to Puppet Users
I decided to try and modify an existing NFS module (puppet-nfs) from
GitHub to suit my needs (rather than reinvent the wheel). I'm stuck
on the "ensure" property of "file" -- there is some discussion on the
net (bug reports) that this does not recursively create the directory
structure... hence:


file { '/mnt/foo': ensure => directory }

May not work. So I hacked this together (below). I wonder if the
file and exec are redundant here. I would think if I specified
"recurse => true" to the file operator that it "should" recursively
create.

The goal here is to create the mount point and NFS mount, then, when
needed, remove it including the directory.

Suggestions welcomed. Thanks!



_F



#
# code
#

define nfs::mount($ensure=present,
$server,
$share,
$mountpoint,
$client_options="tcp,hard,intr,rw,bg") {


mount {"$share":
device => "${server}:${share}",
fstype => "nfs",
name => "${mountpoint}",
options => $client_options,
remounts => true,
atboot => true,
}

case $ensure {
present: {
exec {"create ${mountpoint}":
command => "mkdir -p ${mountpoint}",
unless => "test -d ${mountpoint}",
}

# Is this redundant?
file { ${mountpoint}:
ensure => directory,
owner => "filecopy",
group => "staff",
mode => "775",
}

Mount["$share"] {
require => [Exec["create ${mountpoint}"],
Class["nfs::client"]],
ensure => mounted,
}
}

absent: {
file { ${mountpoint}:
ensure => absent,
force => true,
require => Mount["$share"],
}
Mount["$share"] {
ensure => unmounted,
}
}
}

}

Reply all
Reply to author
Forward
0 new messages