I’ve been writing a lot about Augeas and all the process i go through to get it included in debian/ubuntu. It seems that a lot of people was following it, but some of them don’t actually understand the whole picture and what is augeas for, so i’ve been asked to write a post explaining what it is, so here we go:
From the upstream homepage:
Augeas is a configuration editing tool. It parses configuration files in their native formats and transforms them into a tree. Configuration changes are made by manipulating this tree and saving it back into native config files.
Actually, it is a library which does all that stuff and can be manipulated using its public API. But what does this actually means? I will explain it using augtool and /etc/hosts as an example. As you might know it has the information of the host names and their IP addresses, so let’s take this hosts as an example:
127.0.0.1 localhost localhost.localdomain host.domain
After parsing it on augeas we will end with:
/files/etc/hosts/
- - - - - - - - - - - 1/
- - - - - - - - - - - - ipaddr = 127.0.0.1
- - - - - - - - - - - - canonical = localhost
- - - - - - - - - - - - alias = localhost.localdomain
- - - - - - - - - - - - alias = host.domain
So, then we might want to change some values:
augtool> set /files/etc/hosts/1/alias[2] myhost.domain
Ending with:
/files/etc/hosts/
- - - - - - - - - - - 1/
- - - - - - - - - - - - ipaddr = 127.0.0.1
- - - - - - - - - - - - canonical = localhost
- - - - - - - - - - - - alias = localhost.localdomain
- - - - - - - - - - - - alias = myhost.domain
or add new values:
augtool> ins alias after /files/etc/hosts/1/alias[1]
what will turn into:
/files/etc/hosts/
- - - - - - - - - - - 1/
- - - - - - - - - - - - ipaddr = 127.0.0.1
- - - - - - - - - - - - canonical = localhost
- - - - - - - - - - - - alias = localhost.localdomain
- - - - - - - - - - - - alias
- - - - - - - - - - - - alias = myhost.domain
then we need to set a value since now it’s NULL:
augtool> set /files/etc/hosts/1/alias[2] myhost
ending like:
/files/etc/hosts/
- - - - - - - - - - - 1/
- - - - - - - - - - - - ipaddr = 127.0.0.1
- - - - - - - - - - - - canonical = localhost
- - - - - - - - - - - - alias = localhost.localdomain
- - - - - - - - - - - - alias = myhost
- - - - - - - - - - - - alias = myhost.domain
Then you can save it using:
augtool> save
Also you can add a new host, or whatever you want, just need to play with the tree.
Ok, but how this Black Magic work and how can i expand it to read new configuration files? Augeas uses lenses which are a Meta Data type using regular expressions that is being used for parsing, reading and writing configuration files. If you want to play around with lenses you can check this step-by-step tutorial written by Raphael Pinson (Thank you!)






