Scroll to navigation

Config::Model::Backend::Augeas(3pm) User Contributed Perl Documentation Config::Model::Backend::Augeas(3pm)


Config::Model::Backend::Augeas - Read and write config data through Augeas


  # model specification with augeas backend
   config_class_name => 'OpenSsh::Sshd',
   read_config  => {
      backend => 'augeas' ,
      file => '/etc/ssh/sshd_config',
      # declare "seq" Augeas elements
      sequential_lens => [/AcceptEnv AllowGroups [etc]/],
   # config is written back using read_config specifications
   element => ...


This class provides a way to load or store configuration data through Config::Augeas. This way, the structure and comments of the original configuration file are preserved.

To use Augeas as a backend, you must specify the following "read_config" parameters:

Use "augeas" (or "Augeas")in this case.
Either "backup" or "newfile". See "Constructor" in Config::Augeas for details.
Name of the configuration file.
This one is tricky. Set to one when new Augeas list or hash node must be created for each new list or hash element. See "Sequential lens" for details.

For instance:

   read_config  => {
       backend => 'augeas' ,
       save   => 'backup',
       file => '/etc/ssh/sshd_config',
       # declare "seq" Augeas elements
       sequential_lens => [/AcceptEnv AllowGroups/],

Sequential lens

Some configuration files feature data that must be written as list or as hash. Depending on the syntax, Augeas list or hash lenses can be written so that new "container" nodes are required for each new element.

For instance, "HostKey" lines can be repeated several times in "sshd_config". Since Augeas must keep track of these several lines, Augeas tree will be written like:


and not:


The "HostKey" node is created several times. A new hostkey must be added with the following syntax:


and not:


So the "HostKey" lens is sequential.

The situation is more complex when syntax allow repeated values on several lines. Like:


Augeas will have this tree:


Note that the first index between square brackets keeps track of how the "AcceptEnv" items are grouped, but the real list index is after the slash.

Augeas does not require new elements to create "AcceptEnv[3]". A new element can be added as :


So this lens is not sequential.

The same kind of trouble occurs with hash elements. Some hashes tree are like:


Others are like:


Note that a list-like index is used with the hash key.

This also depends on the syntax of the configuration file. For instance, "Subsystem" in "sshd_config" can be :

 Subsystem   sftp /usr/lib/openssh/sftp-server
 Subsystem   fooftp /usr/lib/openssh/fooftp-server
 Subsystem   barftp /usr/lib/openssh/barftp-server

This (unvalid) sshd configuration is represented by:


Any new Subsystem must be added with:


In this case, the hash is also sequential.

For these examples, the augeas backend declaration must feature:

 sequential_lens => [qw/HostKey Subsystem/],

Augeas backend limitation

The structure and element names of the Config::Model tree must match the structure defined in Augeas lenses. I.e. the order of the element declared in Config::Model must match the order required by Augeas lenses.

Sometimes, the structure of a file loaded by Augeas starts directly with a list of items. For instance "/etc/hosts" structure starts with a list of lines that specify hosts and IP addresses. The "set_in" parameter specifies an element name in Config::Model root class that will hold the configuration data retrieved by Augeas.

Log and trace

This module use Log::Log4perl to log debug and info trace with "Data::Read" and "Data::Write" categories.


Augeas "#comment" nodes are ignored



Dominique Dumont, <ddumont at cpan dot org@<gt>


Copyright (C) 2008-2010 by Dominique Dumont


This library is free software; you can redistribute it and/or modify it under the LGPL terms.

2022-01-07 perl v5.32.1