Augeas editing of fstab

314 views
Skip to first unread message

Anthony Clark

unread,
Mar 20, 2015, 10:20:22 AM3/20/15
to puppet...@googlegroups.com
Hi there,

I'm trying to add the nobarrier option to our XFS mount options in /etc/fstab using Augeas.  I've tried this:

augeas { 'fstabxfsnobarrier': context => '/files/etc/fstab', changes => [ 'rm /*[vfstype="xfs"]/opt', 'ins opt after vfstype="xfs"', 'set /*[vfstype="xfs"]/opt[last()] "defaults"', 'ins opt after vfstype="xfs"', 'set /*[vfstype="xfs"]/opt[last()] "nobarrier"', ], }

But that isn't working. Now in the past I've done something similar with ext4 and /var, which does work:

if defined(Package['mysql55-server']) { augeas { 'fstabvarext4entry': context => '/files/etc/fstab/*[file="/var"][vfstype="ext4"]', changes => [ 'rm opt', 'ins opt after vfstype[last()]', 'set opt[last()] "defaults"', 'ins opt after opt[last()]', 'set opt[last()] "noatime"', 'ins opt after opt[last()]', 'set opt[last()] "data"', 'set opt[last()]/value "writeback"', 'ins opt after opt[last()]', 'set opt[last()] "barrier"', 'set opt[last()]/value "0"', 'ins opt after opt[last()]', 'set opt[last()] "nobh"', 'ins opt after opt[last()]', 'set opt[last()] "errors"', 'set opt[last()]/value "remount-ro"', ], } }

Can Augeas only edit one line at a time, i.e. am I not allowed to do "add this option to every matching line"?

Any help would be greatly appreciated!

Anthony

John Warburton

unread,
Mar 23, 2015, 6:12:48 AM3/23/15
to puppet...@googlegroups.com
On Saturday, March 21, 2015 at 1:20:22 AM UTC+11, Anthony Clark wrote:
Hi there,

I'm trying to add the nobarrier option to our XFS mount options in /etc/fstab using Augeas.  I've tried this:

 Possibly a bit heretical on this list, but I find Augeas is more trouble than it is worth and you are usually better off using templates or native resources

For your case, have you tried managing the mount points with the mount resource and passing the list of options to the options parameter?

John

Wil Cooley

unread,
Mar 23, 2015, 3:16:08 PM3/23/15
to puppet...@googlegroups.com
On Fri, Mar 20, 2015 at 7:20 AM Anthony Clark <dizzy...@gmail.com> wrote:
Hi there,

I'm trying to add the nobarrier option to our XFS mount options in /etc/fstab using Augeas.  I've tried this:

Could you perhaps post working and failing examples of fstab entries?

Wil

Ryan Anderson

unread,
Mar 24, 2015, 8:34:32 AM3/24/15
to puppet...@googlegroups.com
You really ought to try using the 'mount' resource type: http://docs.puppetlabs.com/references/latest/type.html#mount

The native type already knows about /etc/fstab format and is far more cross-platform and simple to use than augeas.

Anthony Clark

unread,
Mar 24, 2015, 1:32:36 PM3/24/15
to puppet...@googlegroups.com
Yeah I've currently got a mounttab block that controls just / and /var, but I'd kind of like to have it run on *any* filesystem that is xfs and mounted in a VM.

This augeas works for single filesystems:

augeas { 'fstabxfsnobarrier':
  context => '/files/etc/fstab/*[file="/var"][vfstype="xfs"]',
  changes => [
    'rm opt',
    'ins opt after vfstype[last()]',
    'set opt[last()] "defaults"',
    'ins opt after opt[last()]',
    'set opt[last()] "nobarrier"',
  ],
}

But if I remove the [file="/var"] then it fails.

But I do have a sort of working solution now.

Raphink

unread,
Mar 29, 2015, 2:32:18 AM3/29/15
to puppet...@googlegroups.com
Actually, the native mount type can also be used with an augeas-based provider if you use the herculesteam/augeasproviders_mounttab module.

This brings the simplicity of a native module with the power and safety of Augeas under the hood.

As for the original code by OP, there are Augeas errors in there. It is possible to achieve this simple option change though, but the nodes in the tree must be ordered properly.


augeas { 'fstabxfsnobarrier':
context => '/files/etc/fstab',
changes => [
'rm /*[vfstype="xfs"]/opt',

You're bypassing the context here by using an absolute path (starting with/). That won't do anything.


'ins opt after vfstype="xfs"',

This syntax is erroneous. You probably mean to insert the opt node after the vfstype node of the matching entry, which would be:

'ins opt after *[vfstype="xfs"]/vfstype


Raphaël
Reply all
Reply to author
Forward
0 new messages