Hi all,<br><br><br>This mail is to introduce a new Perl module based on Augeas and named Config::Augeas::Validator [0].<br><br><br>Why this module?<br>==============<br><br>Many sysadmins today keep a repository of configuration files from which they deploy to their servers. To prevent configuration breakage, it could be useful to parse and check these configuration files before they get deployed.<br>
The goal of Config::Augeas::Validator is to run unit tests on config files using Augeas as a backend. For example, the module can be plugged to a VCS to be used as a precommit script in order to prevent users from committing broken or bad configurations.<br>
<br><br>How it works<br>==========<br><br>Config::Augeas::Validator can work in two ways: with a single configuration file or with a directory of configuration files.<br><br>Configuration files for Config::Augeas::Validator are INI files. Each of these INI files describes a series of tests to be run on a specific pattern with a specific lens. Config::Augeas::Validator runs each test on the given files and returns errors when tests fail.<br>
<br><br>A very simple example<br>==================<br><br>Here is a very simple example, using no rules:<br><br>[DEFAULT]<br>rules=<br>lens=Hosts<br>pattern=.*/hosts<br><br><br>What will this do? When Config::Augeas::Validator is called on a file named "hosts", it will try to parse it using the "Hosts" lens. If the parsing fails, Config::Augeas::Validator will return an error.<br>
<br><br>Making it a bit more complex<br>======================<br><br>[DEFAULT]<br>rules=localhost<br>lens=Hosts<br>pattern=.*/hosts<br><br>[localhost]<br>name=Localhost<br>explanation=IPv4 must be set for localhost<br>type=count<br>
expr=$file/*[ipaddr = "127.0.0.1"][canonical = "localhost"]<br>value=1<br><br><br>Here, I've added a very simple rule checking that the given file contains one and only one entry matching both "localhost" and "127.0.0.1". If this condition is not met, the test will fail.<br>
<br><br>What does the output look like?<br>========================<br><br>Here is an example running the augeas-validator tool.<br><br>$ augeas-validator -r validator-rules configurations/default/generic/disk_config/V_ENCOM_SPUP_FILER_REC<br>
W: File configurations/default/generic/disk_config/V_ENCOM_SPUP_FILER_REC<br>W: Assertion 'noatime for logs' of type count returned 1 for file configurations/default/generic/disk_config/V_ENCOM_SPUP_FILER_REC, expected 0:<br>
   Log partitions should be set to noatime.<br><br><br><br>To infinity and beyond<br>================<br><br>Augeas already supports a lot of lenses, so the possibilities are endless. The main problem I'm facing is simplifying the expr interface for complex tests. An example of a complex test is the following:<br>
<br>[bootable_flag]<br>name=Bootable flag<br>explanation=At least one partition must be bootable<br>type=count<br>expr=$file/disk_config[. != "lvm"][. != "raid"][. != "tmpfs"][count(raw-disk) = 0][count(../disk_config/bootable) = 0]<br>
value=0<br>level=warning<br><br><br>Paths can easily get complex when conditions accumulate, and I'm open to suggestions to simplify this.<br><br>If you wish to clone the repository and play with it, you will find the code on github [1]<br>
<br><br>Cheers,<br><br><br>Raphaël<br><br><br>[0] <a href="http://search.cpan.org/~raphink/Config-Augeas-Validator-0.103/">http://search.cpan.org/~raphink/Config-Augeas-Validator-0.103/</a><br>[1] <a href="https://github.com/raphink/config-augeas-validator">https://github.com/raphink/config-augeas-validator</a><br>