ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Configuration surgery
with Augeas

Dominic Cleal
dcleal@redhat.com
OggCamp 12, Liverpool
19th August 2012


Presentation forked from Rapha?l Pinson's at RMLL 2012
Tired of ugly sed and awk one liners?


or of using tons of different parsing libraries or
brittle tricks?




                   OggCamp | 2 | Dominic Cleal
Become a configuration surgeon with



          Augeas


           OggCamp | 3 | Dominic Cleal
What is the need?




¡ñ   Many different syntaxes
¡ñ   Securely editing configuration files with a
    unified API




                   OggCamp | 4 | Dominic Cleal
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
Augeas provides many stock parsers

They are called lenses:
Access          Cron                            Host_Conf
Aliases         Crypttab                        Hostname
Anacron         debctrl                         Hosts_Access
Approx          Desktop                         IniFile
AptConf         Dhcpd                           Inputrc
Automaster      Dpkg                            Iptables
Automounter     Exports                         Kdump
BackupPCHosts   FAI_DiskConfig                  Keepalived
cgconfig        Fonts                           Keepalived
cgrules         Fuse                            Login_defs
Channels        Grub                            Mke2fs
...

$ augtool print /augeas//path | wc -l
788

                  OggCamp | 6 | Dominic Cleal
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
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
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
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
Puppet has a native provider


augeas { '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
Other projects using Augeas



¡ñ   libguestfs
¡ñ   virt-tools, e.g. p2v, v2v
¡ñ   NUT
¡ñ   ZYpp
¡ñ   Config::Model
¡ñ   Augeas::Validator




                    OggCamp | 13 | Dominic Cleal
Questions?




     http://augeas.net
augeas-devel@redhat.com
   freenode: #augeas




      OggCamp | 14 | Dominic Cleal

More Related Content

Configuration surgery with Augeas (OggCamp 12)

  • 1. Configuration surgery with Augeas Dominic Cleal dcleal@redhat.com OggCamp 12, Liverpool 19th August 2012 Presentation forked from Rapha?l Pinson's at RMLL 2012
  • 2. Tired of ugly sed and awk one liners? or of using tons of different parsing libraries or brittle tricks? OggCamp | 2 | Dominic Cleal
  • 3. Become a configuration surgeon with Augeas OggCamp | 3 | Dominic Cleal
  • 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
  • 6. Augeas provides many stock parsers They are called lenses: Access Cron Host_Conf Aliases Crypttab Hostname Anacron debctrl Hosts_Access Approx Desktop IniFile AptConf Dhcpd Inputrc Automaster Dpkg Iptables Automounter Exports Kdump BackupPCHosts FAI_DiskConfig Keepalived cgconfig Fonts Keepalived cgrules Fuse Login_defs Channels Grub Mke2fs ... $ augtool print /augeas//path | wc -l 788 OggCamp | 6 | 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
  • 11. Puppet has a native provider augeas { '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. Other projects using Augeas ¡ñ libguestfs ¡ñ virt-tools, e.g. p2v, v2v ¡ñ NUT ¡ñ ZYpp ¡ñ Config::Model ¡ñ Augeas::Validator OggCamp | 13 | Dominic Cleal
  • 13. Questions? http://augeas.net augeas-devel@redhat.com freenode: #augeas OggCamp | 14 | Dominic Cleal