[augeas-devel] Adding error handling

Raphaël Pinson raphink at gmail.com
Mon Nov 28 14:29:29 UTC 2011


On Mon, Nov 28, 2011 at 3:04 PM, Graham Leggett <minfrin at sharp.fm> wrote:
> After making a first attempt at getting augeas to work together with puppet, I found myself in a situation where postfix's main.cf configuration file would work, but included ldap templates wouldn't. Augeas+puppet went through all the motions, but made no changes to the ldap templates, even though the main.cf file substitution worked fine.
>
> Eventually, after much reverse engineering of puppet and of augeas,

If you don't like things to get on your nerves, you're always welcome
to ask questions on #augeas on Freenode.


> I discovered that augeas is only able to discover which lens maps to what file by looking up hard coded file locations in each lens.

Yes, there is no other way, and you wouldn't like it otherwise.
Imagine if the detection was automatic, and your file only contained a
typical comment line:

# This is a comment


It could be detected as pretty much anything (IniFile, Shellvars,
Phpvars, etc.), but you wouldn't be able to modify it unless you knew
what lens to use.


> If no lens matches, augeas silently succeeds, leaving the end user none the wiser as to what was wrong and why nothing is happening.
>

Or rather: Augeas has a list of patterns it knows about, and it tries
to apply it to all the files it sees. If files are seen that do not
match, Augeas ignores them. If that wasn't the case, you'd have
warnings/errors for 99.9% of the files on your system.


> An attempt to use augtool to eliminate puppet from the equation showed the same problem - the attempt to edit would silently succeed, the attempt to list would silently list nothing.
>
> Ideally augeas should return some kind of error code to indicate why a particular failure has occured.


Once Augeas has successfully parsed the files it knows about, they end
up in the tree. Now you could want Augeas to yield errors when trying
to access a path which doesn't exist, but then how would you create
new files from scratch? Augeas is perfectly happy letting you create a
new tree in, say, /files/etc/default/foo to create a new file there,
and then letting you save it with its contents.

When should errors happen and they don't happen currently?


> At the same time, it would be ideal if augeas could accept the name of the lens to use as a parameter, so that any file can be edited, not just specific well known files.


It does already. See [0] for how to do it in a generic way. The puppet
provider has an even simpler way to achieve this, by simply using the
"Lens" parameter.


> This limitation significantly reduces the usefulness of the software, as it can only be used for simple config files in well known places, not more complex ones that might be structured in a directory tree using an "include" concept.


Not only can you load files by using the steps provided in [0], but
you can also easily create a new lens which inherits another lens if
you want it to be permanent. Let's say you want to parse MySQL
conffiles located in /home/mysql/conf.ini, you could write a module
like:

module MyMySQL =
autoload xfm
let xfm = transform MySQL.lns (incl "/home/mysql/conf.ini")


Name this mymysql.aug and put it in /usr/share/augeas/lenses, or
wherever you want and add it to the include path (e.g. using the -I
option in augtool), and  you're done.


Cheers,

Raphaël



[0] http://augeas.net/page/Loading_specific_files




More information about the augeas-devel mailing list