Augeas fstab question

320 views
Skip to first unread message

Joe

unread,
Feb 10, 2012, 3:10:56 PM2/10/12
to Puppet Users
I'm trying to add a mount option using puppet/augeas. Something like:

class acl {
augeas { "var_fs_acl":
context => "/files/etc/fstab",
changes => ["ins opt after *[file='/var']/
opt[last()]",
"set *[file='/var']/opt[last()] acl"],
onlyif => "match *[file='/var']/opt[.='acl'] size ==
0"
}
}

This works if /var is a filesystem, but fails if /var is not. Since I
can't have two onlyif clauses, I'm not sure how to say:
If /var is a filesystem and
doesn't already have an opt of acl

Any suggestions would be appreciated.

joe

Christopher Wood

unread,
Feb 10, 2012, 3:15:28 PM2/10/12
to puppet...@googlegroups.com
Try the mount type?

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

(Any particular reason for using augeas?)

> --
> 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.
>
>

David Rolston

unread,
Feb 10, 2012, 5:32:29 PM2/10/12
to puppet...@googlegroups.com
On Fri, Feb 10, 2012 at 12:15 PM, Christopher Wood <christop...@pobox.com> wrote:
Try the mount type?

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

(Any particular reason for using augeas?)

On Fri, Feb 10, 2012 at 12:10:56PM -0800, Joe wrote:
> I'm trying to add a mount option using puppet/augeas. Something like:
>
> class acl {
>         augeas { "var_fs_acl":
>                 context => "/files/etc/fstab",
>                 changes => ["ins opt after *[file='/var']/
> opt[last()]",
>                             "set *[file='/var']/opt[last()] acl"],
>                 onlyif => "match *[file='/var']/opt[.='acl'] size ==
> 0"
>         }
> }
>
> This works if /var is a filesystem, but fails if /var is not. Since I
> can't have two onlyif clauses, I'm not sure how to say:
> If /var is a filesystem and

I second this recommendation -- if it can be done with mount, then that will make things cleaner for you.  Also, I would question the assumption that you can't have multiple onlyif elements.  Most of the time, where you can pass one thing, you can also pass an array, and that works, so you might try that.  However, you can do something like this with a define for example:


class nfsclient {  /// some dependencies I've omitted

 define nfs_mount(
                $device,
                $location = "/nfs/nfsa",
                $fstype,
                $owner,
                $group,
                $mode,
                $options = "soft,intr,noatime"
        ){
        file { "${location}/${name}":
                ensure => directory,
                owner => "${owner}",
                group => "${group}",
                mode => "${mode}",
        }
        mount { "${location}/${name}":
                atboot => true,
                ensure => "mounted",
                device => "${device}",
                fstype => "${fstype}",
                options => "${options}",
                pass => "2",
                require => File["${location}/${name}"],
        }
  }
  nfs_mount { "nfsvol1":
                device => "nfsa.internal.site.com:/nfsvol1",
                fstype => "nfs",
                owner => "root",
                mode => "777",
                options => "soft,intr,noatime",
                subscribe => File['/etc/idmapd.conf'],
  }
}


Dominic Cleal

unread,
Feb 10, 2012, 6:28:27 PM2/10/12
to puppet...@googlegroups.com

Try this:

augeas { "var_fs_acl":
context => "/files/etc/fstab",
changes => [

"ins opt after *[file='/var']/opt[last()]",


"set *[file='/var']/opt[last()] acl",
],

onlyif => "match *[file='/var' and count(opt[.='acl'])=0] size > 0",
}

The idea is that the match condition in onlyif will return the /var
node, only when it has no "acl" opt nodes beneath it.

While the above may work, I'd urge you to consider how you configure
systems with Puppet. Detecting the current configuration (i.e. does or
doesn't have /var) before applying changes is best done with custom
facts or only applying the class to nodes that are supposed to have
/var, rather than complex "onlyif" workarounds on resources.

Hope that helps,

--
Dominic Cleal
Red Hat Consulting
m: +44 (0)7817 878113

Reply all
Reply to author
Forward
0 new messages