Thursday, March 8, 2012

Tip: Puppet augeas provider skips files

I was writing a Puppet class using the augeas provider and found a case where the manifest would work sometimes, but not other times, resulting in a silent error, revealed only by a debug message:
Skipping because no files were changed
I started with this, and it worked sometimes:
augeas {"automaster$name": context => "/files/etc/auto.master", changes => $changes, onlyif => "match map[. = '/$name'] size == 0" }
In some cases it did not work, saying "Skipping because no files were changed" even though debugging showed that changes were made. This version works all the time:
augeas {"automaster$name": context => "/files/etc/auto.master", incl => "/etc/auto.master", lens => "Automaster.lns", load_path => "/var/lib/puppet/lib/augeas/lenses", changes => $changes, onlyif => "match map[. = '/$name'] size == 0" }
I'm not yet sure why this happened, but it seems the difference is that in a manifest where augeas is used previously with load_path, that I need to use it here too.

2 comments:

  1. Hi,

    Can you post your Automaster.lns ?

    ReplyDelete
    Replies
    1. Sorry it took me so long to notice this. Here's my lens if you still want it:

      module Automaster =
      autoload xfm

      let eol = Util.eol
      let comment = Util.comment
      let empty = Util.empty

      let mount_point = store /\/[^# \t\n]+/
      let include = [ label "include" .
      del /\+[ \t]*/ "+" .
      store /[^# \t\n]+/ .
      eol ]
      let options = [ label "options" . store /-[^ \t\n]+/ ]
      let map_param =
      let name = [ label "name" . store /[^: \t\n]+/ ]
      in let type = [ label "type" . store /[a-z]+/ ]
      in let format = [ label "format" . store /[a-z]+/ ]
      in let options = [ label "options" . store /[^ \t\n]+/ ]
      in let prelude = ( type .
      ( del "," "," . format ) ? .
      del ":" ":" )
      in ( prelude ? .
      name .
      ( Util.del_ws_spc . options ) ? )
      let map_record = [ label "map" .
      mount_point . Util.del_ws_spc .
      map_param .
      eol ]

      let lns = ( map_record |
      include |
      comment |
      empty ) *

      let relevant = (incl "/etc/auto.master") .
      Util.stdexcl
      let xfm = transform lns relevant

      Delete