[augeas-devel] puppet and Augeas

Dominic Cleal dcleal at redhat.com
Thu Jun 2 09:02:27 UTC 2011


On 01/06/11 21:36, Glenn Buckholz wrote:
> I've RTFMed as best I can but I am missing something. Is there a way in
> puppet to have Augeas set a variable value or create a list of values
> based on a match? Currently I'm writing my own puppet type to do
> something like this but there are limitations.
> 
> What I'm looking for is something like:
> 
>  augeas {
>    "set some var":
> 
>      val=> "match /files/etc/my.cnf/target[ . =
> \"mysqld\"]/allow-suspicious-udfs size > 0",
>      var=> $myvar
>  }
> 
> where $myvar would maintain that value in its scope.
> 
> Does this exist and I'm just looking in the wrong place?

It doesn't exist because the order of execution in Puppet wouldn't
permit it.  Puppet compiles the catalog, containing all of the resources
and then sends it to the client for execution of those resources, so
it's too late by that point to create new variables that affect the
catalog compilation.

What you need to do instead is create a custom fact that is executed by
the client and sent to the master as the first step, before the catalog
is compiled.

http://projects.puppetlabs.com/projects/puppet/wiki/Adding_Facts

Here's a simple fact that uses the ruby-augeas API:

Facter.add('myvar') do
  setcode do
    require 'augeas'
    aug = Augeas::open('/', nil, Augeas::NONE)
    result = aug.match('/files/etc/fstab/*[file = "/foo"]').size > 0
    aug.close
    result
  end
end

You can adapt this to your match expression and the fact name is defined
by the Facter.add call at the top.  This means it'll be available as
$myvar in the Puppet manifest.

Hope that helps.

-- 
Dominic Cleal
Red Hat Consulting
m: +44 (0)7818 512168




More information about the augeas-devel mailing list