Lightning talk for an intro to Augeas at OggCamp 12. Briefly explains the library, examples of what it can do and where it's used. Based on a presentation by Rapha?l Pinson (search for RMLL 2012).
4. What is the need?
¡ñ Many different syntaxes
¡ñ Securely editing configuration files with a
unified API
OggCamp | 4 | Dominic Cleal
5. A tree, its branches and leaves
Augeas turns configuration files into a tree
structure:
/etc/hosts -> /files/etc/hosts
... and their parameters into branches and
leaves:
augtool> print /files/etc/hosts
/files/etc/hosts
/files/etc/hosts/1
/files/etc/hosts/1/ipaddr = "127.0.0.1"
/files/etc/hosts/1/canonical = "localhost"
OggCamp | 5 | Dominic Cleal
7. augtool lets you inspect the tree
$ augtool
augtool> ls /
augeas/ = (none)
files/ = (none)
augtool> print /files/etc/passwd/root/
/files/etc/passwd/root
/files/etc/passwd/root/password = "x"
/files/etc/passwd/root/uid = "0"
/files/etc/passwd/root/gid = "0"
/files/etc/passwd/root/name = "root"
/files/etc/passwd/root/home = "/root"
/files/etc/passwd/root/shell = "/bin/bash"
OggCamp | 7 | Dominic Cleal
8. The tree can be queried using XPath
augtool> print /files/etc/passwd/*[uid='0'][1]
/files/etc/passwd/root
/files/etc/passwd/root/password = "x"
/files/etc/passwd/root/uid = "0"
/files/etc/passwd/root/gid = "0"
/files/etc/passwd/root/name = "root"
/files/etc/passwd/root/home = "/root"
/files/etc/passwd/root/shell = "/bin/bash"
OggCamp | 8 | Dominic Cleal
9. But also modified
$ grep root /etc/fstab
/dev/mapper/vgiridium-lvroot / ext4 defaults 1 1
$ augtool
augtool> match /files/etc/fstab/*[file='/']/opt
/files/etc/fstab/1/opt = defaults
augtool> set /files/etc/fstab/*[file='/']/opt noatime
augtool> match /files/etc/fstab/*[file='/']/opt
/files/etc/fstab/1/opt = noatime
augtool> save
Saved 1 file(s)
augtool> exit
$ grep root /etc/fstab
/dev/mapper/vgiridium-lvroot / ext4 noatime 1 1
OggCamp | 9 | Dominic Cleal
10. Bindings include Perl, Python, Java, PHP, Ruby...
...OCaml, Haskell, Lua, Vala...
#!/usr/bin/env ruby
require 'augeas'
aug = Augeas.open
# Print each mount
aug.match("/files/etc/fstab/*[file]").each do |m|
mount = aug.get("#{m}/file")
dev = aug.get("#{m}/spec")
puts "#{dev} is mounted at #{mount}"
end
# Edit / mount option
aug.set("/files/etc/fstab/*[file='/']/opt",
"noatime")
aug.save!
OggCamp | 10 | Dominic Cleal