Mcollective and Augeas

Infrastructure – Actualités

17 avril 2012 camptocamp

Mcollective is a very useful tool, which often saves us a lot of time, especially when gathering information about nodes. One information one might want to retrieve from nodes is configuration parameters.

Look at this colorful configuration tree!

Look at this colorful configuration tree!

These can be easily retrieved using custom facts, but you probably don’t want to write and deploy new facts every time you need to query a specific configuration parameter.

This is where Augeas gets on the scene. Augeas is already used quite widely in Puppet to modify configuration files. It works pretty much like a configuration scalpel, allowing you to edit precisely the parameter you want, without impacting the rest of the file (and mostly, without having to parse the file syntax). But Augeas can also be used as a powerful, generic parser to retrieve configuration parameters using its XPath language. In our case, it only lacks a remote API. Coupling it with Mcollective would thus provide a great means of accessing specific configuration parameters remotely.

Fortunately, I was not the first to have this idea. Dean Wilson already wrote an Mcollective agent for Augeas, available on github. After a bit of improvement, and the addition of a client-side application, we now have a useful tool to query configuration parameters through Mcollective, in a similar way to that of augtool. The application currently provides two actions: match and count:


$ mco augeas match "/files/etc/mtab/*[file = '/']/vfstype" -F lsbdistcodename=precise

* [ ============================================================> ] 5 / 5

host-a7256c41c4
/files/etc/mtab/1/vfstype = ext4
host-b89d50982a
/files/etc/mtab/1/vfstype = ext4
host-21cbf2a961
/files/etc/mtab/1/vfstype = ext4
host-265d6ed4a4
/files/etc/mtab/1/vfstype = ext4
host-12299c6389
/files/etc/mtab/1/vfstype = ext4


$ mco augeas count "/files/etc/passwd/rpinson" -F operatingsystem=Ubuntu

* [ ============================================================> ] 5 / 5

host-a7256c41c4
0 matches found
host-21cbf2a961
1 matches found
host-b89d50982a
0 matches found
host-265d6ed4a4
1 matches found
host-12299c6389
1 matches found

There are however some files that cannot be easily accessed via Augeas, since they are not in standard (or otherwise fixed) locations. You can associate them manually to Augeas lenses in the Mcollective command, using the --transform option:


$ mco augeas match --transform "Desktop=/usr/share/applications/*.desktop" "//Desktop Entry/Version" -W /host-21cbf2a961/

* [ ============================================================> ] 1 / 1

host-21cbf2a961
/files/usr/share/applications/gnome-sudoku.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/remmina.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/activity-log-manager-ccpanel.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/shotwell-viewer.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/empathy-accounts.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/deja-dup-preferences.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/inkscape.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/clusterssh.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/shotwell.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/junglediskworkgroup.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/htop.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/nact.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/indicator-datetime-preferences.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/gimp.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/deja-dup-ccpanel.desktop/Desktop Entry/Version = 1.0
/files/usr/share/applications/empathy.desktop/Desktop Entry/Version = 1.0

More than one mapping can be added by separating mapping directives with commas.

The code for agent and application can be found on github.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *