NAME
Config::Model::Backend::Augeas - Read and write config data through Augeas
SYNOPSIS
# use with Augeas
$model->create_config_class
(
config_class_name => 'OpenSsh::Sshd',
# try Augeas and fall-back with custom method
read_config => [ { backend => 'augeas' ,
config_file => '/etc/ssh/sshd_config',
# declare "seq" Augeas elements
lens_with_seq => [/AcceptEnv AllowGroups [etc]/],
},
{ backend => 'custom' , # dir hardcoded in custom class
class => 'Config::Model::Sshd'
}
],
# write_config will be written using read_config specifications
element => ...
) ;
DESCRIPTION
This class provides a way to load or store configuration data through Config::Augeas. This way, the structure and commments of the original configuration file will preserved.
To use Augeas as a backend, you must specify the following read_config
parameters:
- backend
-
Use
augeas
(orAugeas
)in this case. - save
-
Either
backup
ornewfile
. See "Constructor" in Config::Augeas for details. - config_file
-
Name of the config_file.
- lens_with_seq
-
This one is tricky. When an Augeas lens use the
seq
keywords in a lens, a special type of list element is created (See http://augeas.net/docs/lenses.html for details on lenses). This special list element must be declared so that Config::Model can use the correct Augeas call to write this list values.lens_with_seq
must be passed a list ref of all lens names that contains aseq
statement.
For instance:
read_config => [ { backend => 'augeas' ,
save => 'backup',
config_file => '/etc/ssh/sshd_config',
# declare "seq" Augeas elements
lens_with_seq => [/AcceptEnv AllowGroups/],
},
],
Augeas backend limitation
The structure and element names of the Config::Model tree must match the structure defined in 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 adresses. The set_in
parameter specifies an element name in Config::Model root class that will hold the configuration data retrieved by Augeas.