On Feb 24, 5:28 pm, cyrus <matthewcer...@gmail.com> wrote:
> Hi:
>
> Using augeas, how do you add a comment to the beginning of a file. I
> know you can use ins but you need to specify a path to insert before
> or after. In my case I can't with 100% certainty say I will no what
> the first line.

Hi Cyrus,

I posted some Augeas examples in the thread "Diff-style patches" a few
days ago, one containing a define to comment files with Augeas which I
use to prepend lined like "Puppet edits this file!" in my modules.
Here it is again:

#====Define: insert_comment
#
#Insert a comment at the top of a file using Augeas.
#
#This is a wrapper around an Augeas function that inserts a comment at
the top
#of any file with a given comment if that comment doesn't exist. You
can override
#the Augeas 'comment' node name but it defaults to '\#comment'. The
'description'
#parameter is only used in the name of the Augeas resource, so it's
for information
#purposes only.
#
#====Parameters
#
#comment:: The contents of the comment to be added.
#file:: The file to comment, must be supported by Augeas.
#description:: Description of the Augeas resource which translates to
it's namevar.
#aug_comment:: The comment node name for this file. Defaults to
'#comment', you need to change this if your augeas lense describes
it's comment nodes differently, like ';comment' or '//comment'.
#load_path:: Load any additional Augeas lense paths.
define insert_comment($comment, $file, $description,
$aug_comment="#comment", $load_path=undef) {
  augeas { "comment ${file} for ${description}":
    context => "/files${file}",
    changes => [
      "ins ${aug_comment} before *[1]",
      "set ${aug_comment}[1] '${comment}'",
    ],
    onlyif => "match ${aug_comment}[.='${comment}'] size == 0",
    load_path => $load_path,
  }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to