
Augeas – A Configuration API - nikolay
http://augeas.net/
======
rdtsc
I used this for configuring RHEL / CentOS machines. Good stuff. Call via
Python API and everything works nicely in one or two lines of code, as opposed
to editing network and other various /etc config files.

~~~
jlgaddis
Yep, I used it heavily three or four years ago for the same thing -- system
configuration files on RHEL boxes -- when I was first getting involved with
and deploying puppet.

Nowadays, though, I primarily use Ansible and its core "lineinfile" module
gives me pretty much the same end result.

------
shaftway
I currently prefer using Protocol Buffers for configuration. You can use their
built-in text formatter [1] to do plain-text configs. The default format isn't
terrible [2], but I've been thinking about using that code as the basis for a
YAML or JSON version.

Then later when you want to automate generating bits of it, you can write
simple Python (or whatever) scripts to transform the data. If you want the
generated stuff to be less obvious or harder to change (just to stop people
who can't help poking configs in production), write it in binary format.

(1) [https://developers.google.com/protocol-
buffers/docs/referenc...](https://developers.google.com/protocol-
buffers/docs/reference/cpp/google.protobuf.text_format) (2)
[http://stackoverflow.com/questions/18873924/what-does-the-
pr...](http://stackoverflow.com/questions/18873924/what-does-the-protobuf-
text-format-look-like)

------
turtleofdeath
So wait, this seems awesome for a reason I can't quite put my finger on. Can
anyone give an explanation as to how it's useful?

~~~
Ao7bei3s
It provides a consistent interface for changing all kinds of configuration
files, making Ansible-style automation easier and more robust.

"Changing" goes beyond "parsing and generating"; e.g. ordering, comments and
formatting are retained.

The alternative would be search-and-replace style edits (not robust), custom
implementations for every format (hard work to get right, especially without
Augeas' infrastructure in place), or being limited to templating entire files.

The list of supported file formats is quite extensive:
[http://augeas.net/stock_lenses.html](http://augeas.net/stock_lenses.html)
(note on naming: lens is a well-known theoretical concept)

It's sad that Augeas is necessary though -- in an ideal world, developers
wouldn't come up with custom ad-hoc file formats or abuse 'sh' and /etc would
be empty by default.

~~~
PaulHoule
Yeah, one of the problems in the computer industry now is that people are
generating config (and other) files with template systems that don't
understand anything about the underlying syntax.

If you can turn the files into parse trees, manipulate them semantically, and
then turn them back into files, that rocks. For instance, right now I am
working with a database that has to have a lot of things configured -- one of
them is how big the buffers should be, which is a function of how much RAM you
have, which in turn depends on the kind of AWS instance my product runs on.

With a smart configuration API I could take a configuration file supplied by
the user and set the buffers to the right size really easily.

~~~
dozzie
> [...] I am working with a database that has to have a lot of things
> configured -- one of them is how big the buffers should be, which is a
> function of how much RAM you have, which in turn depends on the kind of AWS
> instance my product runs on.

Which has nothing to do with the configuration format itself, it only needs
some knowledge when building config files. It can be achieved as easily with a
simple template (that doesn't understand the config it produces!), only
supplied with information local to the system the config is going to work
under. The easiest way is to build the config from a template on the system
it's going to run, but masterful Puppet with its facts database can do it on
the side of commanding server as well.

~~~
PaulHoule
If the template system doesn't understand the semantics of the configuration
file, templates just work because you are lucky. In the case of blending
configuration changes with a user-supplied file, the user can supply a
configuration file instead of a template.

If the system does understand the configuration file, then you can get the
full value out of having a "fact database" that describes the system.

~~~
dozzie
> If the template system doesn't understand the semantics of the configuration
> file, templates just work because you are lucky.

Or because I put appropriate constraints on data filling the template. Integer
fields are the easiest format to handle.

Generating configs with template systems is surprisingly strudy in real world
scenarios, where at least half-competent programmer provides templates for at
least half-competent sysadmin to fill.

> If the system does understand the configuration file, then you can get the
> full value out of having a "fact database" that describes the system.

The problem is that this "full value" is not that much bigger, but the effort
in understanding config file formats is quite large.

~~~
PaulHoule
The work is large because parser generators are designed for systems
programmers and not for application programmers. They haven't advanced much in
terms of usability, thus parsing seems like a much harder problem than it
really is.

------
tekromancr
I have been looking for this for AGES! I have been using template files and
bash scripts that use sed to change values in config files all this time. I
always wondered why there wasn't a plug-able interface for config files

