Jorge Cardona

Self.

Twitter Google+ Github

Augeas is one of the best things I have discover just this year, and I found a tiny chance to write a mini post about adding an option to an already existing entry. At first I tried to build some kind on immutable set of changes, but I couldn’t find it.

I will do it with augtools, in this case I want to add the option barrier=0 to the root:

augtool> match /files/etc/fstab/*[file="/"]/opt[.="barrier"]
  (no matches)
augtool> ins opt after /files/etc/fstab/*[file="/"]/opt[last()]
augtool> set /files/etc/fstab/*[file="/"]/opt[last()] barrier
augtool> set /files/etc/fstab/*[file="/"]/opt[last()]/value 0
augtool> save
Saving failed

I’m using augeas 0.7.2 (Debian stable) we need instead this:

augtool> match /files/etc/fstab/*[file="/"]/opt[.="barrier"]
  (no matches)
augtool> ins opt after /files/etc/fstab/*[file="/"]/opt[last()]
augtool> set /files/etc/fstab/*[file="/"]/opt[last()] "barrier=0"
augtool> save
Saved 1 file(s)

Well, Since I need this to be set using puppet and work with any version, I’ll need this on my puppet:

  # Add barrier=0 to fstab to avoid problems with new kernel.
  if versioncmp($augeasversion, '0.8.0') >= 0 {
    info("Using new version of augeas: $augeasversion")
    $add_barrier_changes = [
    			 'ins opt after *[file = "/"]/opt[last()]',
			 'set *[file = "/"]/opt[last()] barrier',
			 'set *[file = "/"]/opt[last()]/value 0'
      			 ]
  } else {
    info("Using old version of augeas: $augeasversion")
    $add_barrier_changes = [
    			 'ins opt after *[file = "/"]/opt[last()]',
			 'set *[file = "/"]/opt[last()] "barrier=0"',
      			 ]
  }

  # Apply barrier changes.
  augeas { 'add-barrier-option' :
    context => "/files/etc/fstab",
    changes => $add_barrier_changes,
    onlyif  => 'match *[file = "/"]/opt[.="barrier" or .="barrier=0"] size==0'
  }

That’s all what you need to add an option to a fstab entry with puppet, and apparently is the only way.