Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Iterate over array to mount NFS directories
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Forrie  
View profile  
 More options Sep 24 2012, 6:43 pm
From: Forrie <for...@gmail.com>
Date: Mon, 24 Sep 2012 15:43:26 -0700 (PDT)
Local: Mon, Sep 24 2012 6:43 pm
Subject: Iterate over array to mount NFS directories

I have many systems that require NFS mounts for production.  Rather than
have one entry of file{} and mount{} per NFS import, in a *.pp file, I'd
rather set up and iterate over an array.   Looking at the docs, I'm not
quite sure how to do this properly.  We have three groups for which I would
need this (production, development, test) that each have their own NFS
mounts.

here's what I would use:

$server = "server.name.com"
$prefix = "/some/nfs/root"

# array
production = [
              "dir1",
              "dir2",
              "dir3",
              "dir4",
] # etc etc

Then issue a command to iterate and manage those NFS mounts.

Since these change from time-to-time, and require some pruning... I will be
left with "unmanaged" resources (ie: directory mount points) scattered
around that I will need to clean up.  I read through some tickets for
feature requests and got lost in where this is going -- however, to keep
the place neat and clean, I'd like to unmanage the mount points and the
fstab entries after.   The idea of manually doing this from system to
system isn't good.

I'm still new-ish to puppet, so any pointers would be appreciated.

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Bigum  
View profile  
 More options Sep 25 2012, 5:09 am
From: Luke Bigum <Luke.Bi...@lmax.com>
Date: Tue, 25 Sep 2012 10:09:05 +0100
Local: Tues, Sep 25 2012 5:09 am
Subject: Re: [Puppet Users] Iterate over array to mount NFS directories
Hi Forrie,

With regards to your iteration question, you would need to use a defined
type, something like this (untested):

define nfs_mount ( $server, $prefix, $state = "mounted" ) {
     $mount_point = "${prefix}/${name}"

     #If the state is "unmounted" the mount point 'File' is removed
     file { $mount_point:
         ensure => $state ? {
             "unmounted" => absent,
             "absent" => absent,
             default => present,
         }
     }

     mount { $mount_point:
         ensure => $state,
         device => "{$server}:${mount_point}",
     }

}

nfs_mount { $production: server => $server, prefix => $prefix}

See the documentation for the Mount type in Puppet and it's ensure
parameter for possible values for $state in the define above - it's
possible to have entries in /etc/fstab but not actually mounted, which
should satisfy your two stage cleanup, or you can just set $state to
'absent' straight away and clean up the both NFS mount and mount point.
This means you need to maintain two arrays: one of active mount points
and one of decomissioned mounts, however you probably don't need to keep
the decomissioned mounts around for ever, once every server has cleaned
themselves up they can be removed from the manifest.

http://docs.puppetlabs.com/references/latest/type.html#mount

Hope that helps,

-Luke

On 24/09/12 23:43, Forrie wrote:

--
Luke Bigum
Senior Systems Engineer

Information Systems
Ph: +44 (0) 20 3192 2520
luke.bi...@lmax.com | http://www.lmax.com
LMAX, Yellow Building, 1A Nicholas Road, London W11 4AN

FX and CFDs are leveraged products that can result in losses exceeding
your deposit.  They are not suitable for everyone so please ensure you
fully understand the risks involved.  The information in this email is not
directed at residents of the United States of America or any other
jurisdiction where trading in CFDs and/or FX is restricted or prohibited
by local laws or regulations.

The information in this email and any attachment is confidential and is
intended only for the named recipient(s). The email may not be disclosed
or used by any person other than the addressee, nor may it be copied in
any way. If you are not the intended recipient please notify the sender
immediately and delete any copies of this message. Any unauthorised
copying, disclosure or distribution of the material in this e-mail is
strictly forbidden.

LMAX operates a multilateral trading facility.  Authorised and regulated
by the Financial Services Authority (firm registration number 509778) and
is registered in England and Wales (number 06505809).
Our registered address is Yellow Building, 1A Nicholas Road, London, W11
4AN.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Forrie  
View profile  
 More options Sep 25 2012, 6:09 pm
From: Forrie <for...@gmail.com>
Date: Tue, 25 Sep 2012 15:09:13 -0700 (PDT)
Local: Tues, Sep 25 2012 6:09 pm
Subject: Re: [Puppet Users] Iterate over array to mount NFS directories

Thank you for your reply :)

The head of the code would need something like this:

$server = "nfs-server.domain.com"
$prefix = "/our/prefix"

# Arrays to iterate over, which would be a little longer than this
$proddirs = [ "201201", "201202", "201203" ]
$testdirs = [ "201201", "201202", "201203" ]
$devdirs  = [ "201201", "201202", "201203" ]

$nfsopts  = "tcp,hard,intr,rw,bg"

By "iterate" I meant to work through a specific array, such as above.  

Reading through the Mount part of the docs, I don't believe that "absent"
will remove the actual directory point, it says:

"Set it to absent to unmount (if necessary) and remove the filesystem from
the fstab"

So I would handle that by running another iteration over an array for each
section that would have a routine to make sure it's "absent" and then also
rmdir the entry in the filesystem.

I'm not understanding where the below is iterating or over where... as
$name would need to be defined somehow.

Thanks!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Bigum  
View profile  
 More options Sep 26 2012, 4:51 am
From: Luke Bigum <Luke.Bi...@lmax.com>
Date: Wed, 26 Sep 2012 09:51:47 +0100
Local: Wed, Sep 26 2012 4:51 am
Subject: Re: [Puppet Users] Iterate over array to mount NFS directories

Hi Forrie,

My example below uses a defined type
(http://docs.puppetlabs.com/puppet/2.7/reference/lang_defined_types.html) to
group two related resources together, in this case the File resource for
the mount point and the Mount resource for the NFS mount itself.

To answer your first question, no, "ensure=>absent" in a Mount resource
will not remove the mount point directory. That is why I've wrapped the
File and Mount point in a define, so you can use one definition of
nfs_mount to control both mount point and NFS mount together, as in your
scenario they are two closely related resources.

You will notice the $state parameter of my defined type is used in two
places: for the 'ensure' parameter of the Mount (described in the docs
for the Mount type) and the 'ensure' parameter of the File. Since the
ensure parameter of the Mount type takes different arguments to the File
type, I use a selector to transform the Mount point's state into a state
I can use in a File resource. The selector (ensure => $state ? {...} )
basically says this:

"If $state is unmounted, the File is absent"
"If $state is absent, the File is absent"
"If $state is anything else, the File is directory"

file { $mount_point:
          ensure => $state ? {
              "unmounted" => absent,
              "absent" => absent,
              default => directory,
          }

}

I just noticed a bug in my original post, it should be "default =>
directory" to create a directory, not a file :-)

http://docs.puppetlabs.com/puppet/2.7/reference/lang_conditional.html...

As for the second question about the iteration, the iteration works the
same way for a defined type as it does for any core Puppet type (File,
Mount, Service, etc). Although it's not really a procedural "loop", it's
just a short hand way of writing out a set of resource definitions with
exactly the same parameters, but the effect is the same.

So doing these :

file { $proddirs: ... }
mount { $proddirs: ... }

is the same as this:

nfs_mount { $proddirs: ... }

Now the $name parameter or is the namevar of the defined type
(http://docs.puppetlabs.com/puppet/2.7/reference/lang_resources.html#n...).
It's the unique name of the resource, works the same as other Puppet
Types, in the examples below it is the strings "apache" and
"/mnt/server/woof":

package { "apache": }
nfs_mount { "/mnt/server/woof/": }

You can use $name inside a defined type just like any other variable /
parameter.

So in an example use of my defined type, this definition:

nfs_mount{ "201201":
   state  => "mounted",
   server => "nfs-server.domain.com",
   prefix => "/our/prefix",

}

Will result in the following standard Puppet resources:

file { "/our/prefix/201201":
   ensure => "directory",

}

mount { "/our/prefix/201201":
   ensure => "mounted",
   device => "nfs-server.domain.com:/our/prefix/201201",

}

Hopefully that explains the use of the defined type in more detail. If
you have any more questions, please ask :-)

-Luke

On 25/09/12 23:09, Forrie wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Bigum  
View profile  
 More options Sep 27 2012, 4:24 am
From: Luke Bigum <Luke.Bi...@lmax.com>
Date: Thu, 27 Sep 2012 09:23:34 +0100
Local: Thurs, Sep 27 2012 4:23 am
Subject: Re: [Puppet Users] Iterate over array to mount NFS directories

Hi Forrie,

Good to see you are almost there! As you've discovered the "looping" in
Puppet isn't *really* looping, it's just a shorthand way of creating
multiple resources. However, by combining that with a Defined Type, you
can effectively reference the same array element multiple times using
$name in the define - as we do with the File and Mount resources - and
you achieve an approximation of a loop.

Also remember there was a bug in my original post, the File resource
needs "default => directory" to create a directory, not "present", as
that would create a file instead, but it looks like you've figured that
out anyway.

Unfortunately there is no way to recursively create directories in
Puppet. You will need to manage the File[/dce/prod/] directory outside
of the nfs_mount resources. Why? If you have more than one Prod
nfs_mount, you will get duplicate definitions when you try create
/dce/prod/ inside the nfs_mount define.

In your example below you have a class called prod-nfs-mounts. Inside
this class you could have a file { "/dce/prod": ensure => directory }
resource to ensure the parent directory is created.

One mor bug: the Mount resource should have a dependency on the File
resource - you can't mount before the mount point is there. Add a
parameter 'require => File[$mount_point]' to the mount resource in the
define.

Also just so you know, older versions of Puppet don't like dashes (-) in
class and variable names, so I would recommend you use underscores where
possible.

-Luke

On 26/09/12 21:59, Forrest Aldrich wrote:

--
Luke Bigum
Senior Systems Engineer

Information Systems
Ph: +44 (0) 20 3192 2520
luke.bi...@lmax.com | http://www.lmax.com
LMAX, Yellow Building, 1A Nicholas Road, London W11 4AN

FX and CFDs are leveraged products that can result in losses exceeding
your deposit.  They are not suitable for everyone so please ensure you
fully understand the risks involved.  The information in this email is not
directed at residents of the United States of America or any other
jurisdiction where trading in CFDs and/or FX is restricted or prohibited
by local laws or regulations.

The information in this email and any attachment is confidential and is
intended only for the named recipient(s). The email may not be disclosed
or used by any person other than the addressee, nor may it be copied in
any way. If you are not the intended recipient please notify the sender
immediately and delete any copies of this message. Any unauthorised
copying, disclosure or distribution of the material in this e-mail is
strictly forbidden.

LMAX operates a multilateral trading facility.  Authorised and regulated
by the Financial Services Authority (firm registration number 509778) and
is registered in England and Wales (number 06505809).
Our registered address is Yellow Building, 1A Nicholas Road, London, W11
4AN.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »