Augeas fstab - removing all opt nodes then rebuilding

211 views
Skip to first unread message

Anthony Clark

unread,
Feb 4, 2015, 10:15:29 AM2/4/15
to puppet...@googlegroups.com
Hello All,

I have a requirement to mount /var with specific options if mysql-server is installed and the filesystem is ext4.  So far I have this:

  if defined(Package['mysql55-server']) {
    notice
"found mysql server"
   
    augeas
{ 'fstabvarentry':
      context
=> '/files/etc/fstab/*[file="/var"][vfstype="ext4"]',
      changes
=> [
       
'', # remove all opt nodes
       
'ins opt[1] "defaults"',
       
'ins opt[2] "noatime"',
       
# etc etc to build "defaults,noatime,data=writeback,barrier=0,nobh,errors=remount-ro"
     
],
      onlyif  
=> 'match /files/etc/fstab/*[file="/var"][vfstype="ext4"]',
   
}
 
}

Now, my problem is how to deal with all possible opt entries for the /var partition.  I want to start off by removing *all* opt nodes then adding the ones I need, but I am having trouble finding the syntax on how to remove all opt nodes.

How can I write "rm opt*" ?

Thanks!

jamese

unread,
Feb 4, 2015, 10:37:20 AM2/4/15
to puppet...@googlegroups.com
with augtool you can do the following:

augtool> ls /files/etc/fstab/3/
spec = UUID=XXXX
file = /boot/efi
vfstype = vfat
opt[1]/ = umask
opt[2]/ = shortname
dump = 0
passno = 0
augtool> rm  /files/etc/fstab/3/opt[*]
rm : /files/etc/fstab/3/opt[*] 4
augtool> ls /files/etc/fstab/3/
spec = UUID=XXXX
file = /boot/efi
vfstype = vfat
dump = 0
passno = 0
augtool>

I believe in the augeas resource you can do "rm opt[*]" for the same result.  I'd be sure you have a backup of the file before doing this on a real box :)

Anthony Clark

unread,
Feb 4, 2015, 10:39:16 AM2/4/15
to puppet...@googlegroups.com
Running the following gives me an error:

    augeas { 'fstabvarentry':
      context
=> '/files/etc/fstab/*[file="/var"][vfstype="ext4"]',
      changes
=> [

       
'set opt[1] "default"',
       
'set opt[2] "noatime"',
       
'set opt[3] "data"',
       
'set opt[3]/value "writeback"',
       
'set opt[4] "barrier"',
       
'set opt[4]/value "0"',
       
'set opt[5] "nobh"',  
       
'set opt[6] "errors"',  
       
'set opt[6]/value "remount-ro"',  
     
],
     
#onlyif  => 'match /files/etc/fstab/*[file="/var"][vfstype="ext4"]',
   
}




Debug: Augeas[fstabvarentry](provider=augeas): /augeas/files/etc/fstab/error/message = Failed to match
   
{ /spec/ = /[^\001-\004\t\n #,][^\001-\004\t\n ]*/ }{ /file/ = /[^\001-\004\t\n #]+/ }{ /vfstype/ = /[^\001-\004\t\n #,=]+/ }({ /vfstype/ = /[^\001-\004\t\n #,=]+/ })*({ /opt/ = /[^\001-\004\t\n #,=]+/ }({ /opt/ = /[^\001-\004\t\n #,=]+/ })*({ /dump/ = /[0-9]+/ }({ /passno/ = /[0-9]+/ })?)?)?({ /#comment/ = /[^\001-\004\t\n\r ][^\001-\004\n]*[^\001-\004\t\n\r ]|[^\001-\004\t\n\r ]/ } | ())
 
with tree
   
{ "spec" = "/dev/mapper/vg_01-lv_var01" } { "file" = "/var" } { "vfstype" = "ext4" } { "opt" = "default" } { "dump" = "1" } { "passno" = "2" } { "opt" = "noatime" } { "opt" = "data" } { "opt" = "barrier" } { "opt" = "nobh" } { "opt" = "errors" }
Debug: Augeas[fstabvarentry](provider=augeas): Closed the augeas connection
Error: /Stage[main]/Wnp::Fusion::Mysql_server55/Augeas[fstabvarentry]: Could not evaluate: Saving failed, see debug

Anthony Clark

unread,
Feb 4, 2015, 11:16:29 AM2/4/15
to puppet...@googlegroups.com
This worked for me, thanks for the help:

  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"',
     
],
   
}
 
}
Reply all
Reply to author
Forward
0 new messages