Manage /etc/fstab option with Puppet and Augeas

1,077 views
Skip to first unread message

Mitja Mihelič

unread,
Apr 3, 2015, 1:18:39 PM4/3/15
to puppet...@googlegroups.com
Hi!

I am trying to accomplish a seemigly simple task, currently without any success. And so multiple questions come to mind.

A line in fstab should be checked each puppet runs and set it back to it's predefined state.
gluster1:/gvol   /mnt/gluster    glusterfs defaults,transport=tcp,backup-volfile-servers=gluster2:gluster3  0 0

This should change the mountpoint (file) value back to whatever was set in $mountpoint.
        augeas { "gluster-fstab-mod-mountpoint":
                context => "/files/etc/fstab",
                changes => [
                        "set *[file = '/mnt/gluster']/file '$mountpoint'",
                ],
                onlyif => [
                        "match *[spec = '$server:/$volume']",
                        "match *[file = '$mountpoint']",
                        "match *[vfstype = 'glusterfs']",
                ]
        }
I could do this by having such a block for each of the options (spec, file, vfstype). Can it be done any other way?

How do I go about changing the mount options (defaults,transport=tcp,backup-volfile-servers=gluster2:gluster3)?
If someone adds options to /etc/fstab manually, I'd like to remove them. If options are changed, I'd like to reset them. If deleted, add them.
How can I do that?

Regards,
Mitja

Daniel Dreier

unread,
Apr 3, 2015, 2:53:30 PM4/3/15
to puppet...@googlegroups.com
Mitja -

Can you use the native mount type (https://docs.puppetlabs.com/references/latest/type.html#mount) for this? If you manage all mount points using puppet's mount type and then enable purge on mount resources (dangerous! test first - not in production) it should do what you're looking for, if I understand what you're looking to accomplish.
 

--
Daniel Dreier
Technical Operations Engineer
GPG: BA4379FD

Christopher Wood

unread,
Apr 4, 2015, 1:13:15 AM4/4/15
to puppet...@googlegroups.com
On Fri, Apr 03, 2015 at 11:40:36AM -0700, Daniel Dreier wrote:
> On Fri, Apr 3, 2015 at 10:15 AM, Mitja Mihelič <[1]mmih...@gmail.com>
> ([2]https://docs.puppetlabs.com/references/latest/type.html#mount) for
> this? If you manage all mount points using puppet's mount type and then
> enable purge on mount resources (dangerous! test first - not in
> production) it should do what you're looking for, if I understand what
> you're looking to accomplish.

Quoth, "Puppet will try to unmount then remount that filesystem". This seems to be true for mount option changes in the resource too. The problem is that if there's a filehandle pointing into the filesystem the unmount will fail and the filesystem will keep its previous options. Some kind of 'mount -o remount,and,other,options' on resource changes rather than creation would have to be available through something other than the mount type.

(Also, a remount,etc sort of provider seems to be asking for trouble, how will you know which filehandles' processes are safe to kill?)

> --
> Daniel Dreier
> Technical Operations Engineer
> GPG: BA4379FD
>
> --
> 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 [3]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [4]https://groups.google.com/d/msgid/puppet-users/CAGk8suZxRdwB%2BNO%3DLweq3%2BizFsoCJw7TxVtnLMck_%3DtP2dfk6g%40mail.gmail.com.
> For more options, visit [5]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. mailto:mmih...@gmail.com
> 2. https://docs.puppetlabs.com/references/latest/type.html#mount
> 3. mailto:puppet-users...@googlegroups.com
> 4. https://groups.google.com/d/msgid/puppet-users/CAGk8suZxRdwB%2BNO%3DLweq3%2BizFsoCJw7TxVtnLMck_%3DtP2dfk6g%40mail.gmail.com?utm_medium=email&utm_source=footer
> 5. https://groups.google.com/d/optout

Mitja Mihelič

unread,
Apr 7, 2015, 4:08:27 AM4/7/15
to puppet...@googlegroups.com, christop...@pobox.com
Thanks to both posters, but I decided against using the native mount type. In part I wanted a bit of practice with Augeas and as Christopher wrote, remounting is not safe.

Well, I stuck with my module and ended up with something that is not the prettiest piece of code, but does the trick. No auto-remounts though!


define glusterfs::mount (
$server = "",
$volume = "",
$peers = "",
$mountpoint = "/mnt/gluster",
$dump = "0",
$pass = "0",
$description = "GlusterFS mount",
)
{
###############################################################################
# native augeas nodes for fstab + input variables
# spec = $server:/$volume
# file = $mountpoint
# vmfstype = glusterfs
# opt = defaults,transport=tcp,backup-volfile-servers=$peers
# dump = 0
# passno = 0
###############################################################################
# install augeas package as dependency for everything
package { 'augeas':
ensure   => present,
provider => yum
}

# create mountpoint
file { "$mountpoint": 
ensure => "directory",
owner   => root,
group   => root,
mode    => '0755',
}

# fstab
augeas { "gluster-fstab-add":
context => "/files/etc/fstab",
changes => [
"set #comment[last()+1] '$description'",
"set 01/spec '$server:/$volume'",
"set 01/file '$mountpoint'",
"set 01/vfstype 'glusterfs'",
"set 01/opt[1] 'defaults'",
"set 01/opt[2] 'transport'",
"set 01/opt[2]/value 'tcp'",
"set 01/opt[3] '_netdev'",
"set 01/opt[4] 'backup-volfile-servers'",
"set 01/opt[4]/value '$peers'",
"set 01/dump '$dump'",
"set 01/passno '$pass'",
],
onlyif => [
"match *[file = '$mountpoint'] size == 0",
]
}

augeas { "gluster-fstab-set-peers":
context => "/files/etc/fstab",
changes => [
"set *[spec = '$server:/$volume'][file = '$mountpoint'][vfstype = 'glusterfs']/opt[. = 'backup-volfile-servers']/value '$peers'",
],
}
augeas { "gluster-fstab-add-peers":
context => "/files/etc/fstab",
changes => [
"ins opt after *[spec = '$server:/$volume'][file = '$mountpoint'][vfstype = 'glusterfs'][count(opt[. = 'backup-volfile-servers']) = 0]/opt[last()]",
"set *[spec = '$server:/$volume'][file = '$mountpoint'][vfstype = 'glusterfs'][count(opt[. = 'backup-volfile-servers']) = 0]/opt[last()] backup-volfile-servers",
"set *[spec = '$server:/$volume'][file = '$mountpoint'][vfstype = 'glusterfs'][count(opt[. = 'backup-volfile-servers']) = 1]/opt[last()]/value '$peers'",
],
onlyif => [
"match *[spec = '$server:/$volume'][file = '$mountpoint'][vfstype = 'glusterfs'][opt = 'backup-volfile-servers'] size == 0",
]
}

augeas { "gluster-fstab-set-transport":
context => "/files/etc/fstab",
changes => [
"set *[spec = '$server:/$volume'][file = '$mountpoint'][vfstype = 'glusterfs']/opt[. = 'transport']/value 'tcp'",
],
}
augeas { "gluster-fstab-add-transport":
context => "/files/etc/fstab",
changes => [
"ins opt after *[spec = '$server:/$volume'][file = '$mountpoint'][vfstype = 'glusterfs'][count(opt[. = 'transport']) = 0]/opt[last()]",
"set *[spec = '$server:/$volume'][file = '$mountpoint'][vfstype = 'glusterfs'][count(opt[. = 'transport']) = 0]/opt[last()] transport",
"set *[spec = '$server:/$volume'][file = '$mountpoint'][vfstype = 'glusterfs'][count(opt[. = 'transport']) = 1]/opt[last()]/value 'tcp'",
],
onlyif => [
"match *[spec = '$server:/$volume'][file = '$mountpoint'][vfstype = 'glusterfs'][opt = 'transport'] size == 0",
]
}
}



Reply all
Reply to author
Forward
0 new messages