handling of network mounts using puppet

310 views
Skip to first unread message

ddn...@gmail.com

unread,
Dec 9, 2015, 9:24:41 AM12/9/15
to Puppet Users
Hello Group,


I am working on a module to handle mounting of NFS mounts.
Puppet: 3.7.1
Hiera: 1.3.4

I have already tested it in my lab machine and it works as expected:

mytestserver.example.com.yaml
nfsmounts:
   
'/net1':
        path
: '/net1'
        device
: 'somefiler:/vol/vol1/test1'
   
'/net2':
        path
: '/net2'
        device
: 'nfsserver:/data/test2'
   
'/net3':
        path
: '/net3'
        device
: '192.168.0.100:/local/foo/test3'


init.pp  
class mynfsmounts {
    $nfsmounts_hash
= hiera_hash('nfsmounts')
    create_resources
('mynfsmounts::mounts',$nfsmounts_hash )
}

mounts.pp
define mynfsmounts::mounts ($path,$device,)
{
    $mountopts
= 'rw,_netdev'
    $owner
= 'admuser'
    $group
= 'admuser'

    mount
{ $name:
       
ensure   => 'mounted',
        device  
=> $device,
        fstype  
=> 'nfs',
        options  
=> $mountopts,
        atboot  
=> 'yes',
       
require  => File[$title],
   
}
 
    file
{ $title:
       
ensure  => directory,
        owner  
=> $owner,
       
group   => $group,
        mode    
=> '2775',
   
}

}


My question is, how do I separate the file and the mount resources in a separate manifest inside the same module and have the same effect? Our puppet admins require that defined type declarations do not include resources inside them.



Martin Alfke

unread,
Dec 9, 2015, 10:12:31 AM12/9/15
to puppet...@googlegroups.com
Hi,
Wow.
A self defined resource type purely makes use of existing resource types.
Why are you allowed to have the mount resource in the define but not the file resource declaration?


ddn...@gmail.com

unread,
Dec 9, 2015, 12:04:20 PM12/9/15
to Puppet Users
Hi Martin, I'm not sure what you mean. Both the mount and file resource are in the defined type.

Martin Alfke

unread,
Dec 9, 2015, 12:19:15 PM12/9/15
to puppet...@googlegroups.com

On 09 Dec 2015, at 17:04, ddn...@gmail.com wrote:

> Hi Martin, I'm not sure what you mean. Both the mount and file resource are in the defined type.

yes. But you mentioned in your first email:
"Our puppet admins require that defined type declarations do not include resources inside them.”

Your question: "My question is, how do I separate the file and the mount resources in a separate manifest inside the same module and have the same effect?”

Why would you like to do this?
What is wrong with having file and mount in the define?
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/06fa7c46-4d53-4cc5-9f4a-1b4eed17da23%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Garrett Honeycutt

unread,
Dec 9, 2015, 2:19:39 PM12/9/15
to puppet...@googlegroups.com
On 12/9/15 9:08 AM, ddn...@gmail.com wrote:
> Hello Group,
>
>
> I am working on a module to handle mounting of NFS mounts.
> *Puppet*: 3.7.1
> *Hiera*: 1.3.4
>
> I have already tested it in my lab machine and it works as expected:
>
> mytestserver.example.com.yaml
> |
> nfsmounts:
> '/net1':
> path:'/net1'
> device:'somefiler:/vol/vol1/test1'
> '/net2':
> path:'/net2'
> device:'nfsserver:/data/test2'
> '/net3':
> path:'/net3'
> device:'192.168.0.100:/local/foo/test3'
> |
>
>
> init.pp
> |
> classmynfsmounts {
> $nfsmounts_hash =hiera_hash('nfsmounts')
> create_resources('mynfsmounts::mounts',$nfsmounts_hash )
> }
> |
>
> mounts.pp
> |
> define mynfsmounts::mounts ($path,$device,)
> {
> $mountopts ='rw,_netdev'
> $owner ='admuser'
> $group ='admuser'
>
> mount {$name:
> ensure =>'mounted',
> device =>$device,
> fstype =>'nfs',
> options =>$mountopts,
> atboot =>'yes',
> require =>File[$title],
> }
>
> file {$title:
> ensure =>directory,
> owner =>$owner,
> group =>$group,
> mode =>'2775',
> }
>
> }
> |
>
>
> My question is, how do I separate the /file/ and the /mount/ resources
> in a separate manifest inside the same module and have the same effect?
> Our puppet admins require that defined type declarations do not include
> resources inside them.
>

Hi,

Checkout ghoneycutt/nfs[1], it already supports a ton of platforms,
though if yours is not supported, I would be happy to work with you to
add support.

If you want to also ensure the directory is there for the mount, I use
ghoneycutt/types[2], which supports NFS and more. An example is here[3].

Like Martin, I'm also a bit confused by your statement regarding the
puppet admins. Hopefully they are encouraging the use of third party
modules as opposed to reinventing the wheel. :) The code you have makes
sense to me, whereas putting the mount and file resources somewhere else
does not make sense at all and seems to be in opposition to why defined
types exist.

[1] - https://github.com/ghoneycutt/puppet-module-nfs
[2] - https://github.com/ghoneycutt/puppet-module-types
[3] - https://github.com/ghoneycutt/puppet-module-types#mount

Best regards,
-g

--
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

jcbollinger

unread,
Dec 10, 2015, 9:21:46 AM12/10/15
to Puppet Users


On Wednesday, December 9, 2015 at 8:24:41 AM UTC-6, ddn...@gmail.com wrote:

[...]
 
My question is, how do I separate the file and the mount resources in a separate manifest inside the same module and have the same effect? Our puppet admins require that defined type declarations do not include resources inside them.


I have to join the others in expressing confusion over this.  Surely there is some sort of misunderstanding here.  I suspect that what your admins really want is the widely accepted standard practice that defined type definitions, such as the one in your mounts.pp, appear in their own manifest files, as opposed to appearing inside or alongside class definitions in those classes' manifests.  In that case, your code already complies.

I don't see how defined types could serve any useful purpose distinct from classes' if they are not permitted to contain resource declarations.  If your Puppet admins truly are demanding that, then get them some training, fast, or else find others who know what they're doing.


John

Reply all
Reply to author
Forward
0 new messages