[augeas-devel] How to use the generic IniFile module?

Dominic Cleal dcleal at redhat.com
Mon Mar 5 10:29:15 UTC 2012


On 05/03/12 09:32, Biltong wrote:
> Hello,
> 
> Is it possible to list all lenses that Augeas supports?

Looking in /usr/share/augeas/lenses/dist is probably your best bet.
Most of the modules have a "lns" lens inside, except where they're
designed as building blocks (e.g. util, rx, build and inifile).

There's also the generated documentation, but it doesn't list all
lenses, as documentation coverage isn't complete yet:

http://augeas.net/docs/references/lenses/

> I'd like to edit a .ini file without defining a new lens. When I try, I
> get an error:
> 
> augtool> set /augeas/load/IniFile/lens inifile
> augtool> set /augeas/load/IniFile/incl /some/file.ini
> augtool> load
> error: Lens not found
> error: Can not find lens inifile
> 
> I can see a inifile.aug in /usr/share/augeas/lenses/dist
> 
> What's going on? Thanks.

Two things here:

a) The IniFile module is a set of building blocks and doesn't contain a
lens that will let you parse a whole file.  The reason for this is .ini
files actually vary somewhat in design, so there's no single generic
lens it provides.

You'd be better off specifying one of the derived lenses, such as:

Puppet.lns - simple .ini file
PHP.lns - allows settings outside of sections (under ".anon")
MySQL.lns - allows slashes in section names, supports !include etc
Dput.lns - allows only certain setting names, allows slashes

For a many cases, Puppet.lns is probably suitable.

b) The "lens" setting should usually be "ModuleName.lns" rather than the
filename "inifile".

So for the puppet.aug file, the "module Puppet" line inside gives you
the module name "Puppet".   The lens inside puppet.aug that represents
the entire config is by convention called "lns" (see the "transform"
line near the bottom), so you instead need to run:

set /augeas/load/IniFile/lens Puppet.lns

Hope that helps.

-- 
Dominic Cleal
Red Hat Consulting
m: +44 (0)7817 878113




More information about the augeas-devel mailing list