Configuration surgery with Augeas (OggCamp 12)

5,503 views

Published on

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).

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,503
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Configuration surgery with Augeas (OggCamp 12)

  1. 1. Configuration surgerywith AugeasDominic Clealdcleal@redhat.comOggCamp 12, Liverpool19th August 2012Presentation forked from Raphaël Pinsons at RMLL 2012
  2. 2. Tired of ugly sed and awk one liners?or of using tons of different parsing libraries orbrittle tricks? OggCamp | 2 | Dominic Cleal
  3. 3. Become a configuration surgeon with Augeas OggCamp | 3 | Dominic Cleal
  4. 4. What is the need?● Many different syntaxes● Securely editing configuration files with a unified API OggCamp | 4 | Dominic Cleal
  5. 5. A tree, its branches and leavesAugeas turns configuration files into a treestructure:/etc/hosts -> /files/etc/hosts... and their parameters into branches andleaves: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
  6. 6. Augeas provides many stock parsersThey are called lenses:Access Cron Host_ConfAliases Crypttab HostnameAnacron debctrl Hosts_AccessApprox Desktop IniFileAptConf Dhcpd InputrcAutomaster Dpkg IptablesAutomounter Exports KdumpBackupPCHosts FAI_DiskConfig Keepalivedcgconfig Fonts Keepalivedcgrules Fuse Login_defsChannels Grub Mke2fs...$ augtool print /augeas//path | wc -l788 OggCamp | 6 | Dominic Cleal
  7. 7. augtool lets you inspect the tree$ augtoolaugtool> 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. 8. The tree can be queried using XPathaugtool> 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. 9. But also modified$ grep root /etc/fstab/dev/mapper/vgiridium-lvroot / ext4 defaults 1 1$ augtoolaugtool> match /files/etc/fstab/*[file=/]/opt/files/etc/fstab/1/opt = defaultsaugtool> set /files/etc/fstab/*[file=/]/opt noatimeaugtool> match /files/etc/fstab/*[file=/]/opt/files/etc/fstab/1/opt = noatimeaugtool> saveSaved 1 file(s)augtool> exit$ grep root /etc/fstab/dev/mapper/vgiridium-lvroot / ext4 noatime 1 1 OggCamp | 9 | Dominic Cleal
  10. 10. Bindings include Perl, Python, Java, PHP, Ruby......OCaml, Haskell, Lua, Vala...#!/usr/bin/env rubyrequire augeasaug = Augeas.open# Print each mountaug.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 optionaug.set("/files/etc/fstab/*[file=/]/opt", "noatime")aug.save! OggCamp | 10 | Dominic Cleal
  11. 11. Puppet has a native provideraugeas { export /foo: context => /files/etc/exports, changes => [ "set dir[. = /foo] /foo", "set dir[. = /foo]/client weeble", "set dir[. = /foo]/client/option[1] ro", "set dir[. = /foo]/client/option[2] all_squash", ],}$ cat /etc/exports/foo weeble(ro,all_squash) OggCamp | 11 | Dominic Cleal
  12. 12. Other projects using Augeas● libguestfs● virt-tools, e.g. p2v, v2v● NUT● ZYpp● Config::Model● Augeas::Validator OggCamp | 13 | Dominic Cleal
  13. 13. Questions? http://augeas.netaugeas-devel@redhat.com freenode: #augeas OggCamp | 14 | Dominic Cleal

×