Augeas, swiss knife resources for your puppet tree
1. .
AAuuggeeaass
SSwwiissss--kknniiffee rreessoouurrcceess ffoorr yyoouurr ppuuppppeett ttrreeee
Julien Pivotto
Belgian Puppet User Group
Holiday is over Meetup!!! - November 12th, 2014
2. .
wwhhooaammii
JJuulliieenn PPiivvoottttoo
• Open-Source consultant at inuits.eu
• FOSS defender since 2004
• DevOps believer and evangelist
• Puppet User since 2011
• @roidelapluie on twitter/github
17. .
FFiillee[[]] bbeehhaavviioouurr
• Array as "source": Puppet will pick the first
available one
• Multiple arguments to template(): Puppet
will concatenate them all
• File[/foo/bar] will autorequire File[/foo]
18. .
DDoowwnnssiiddee ooff FFiillee[[]]
• You can only have at one "content"
• That resource describe the whole file
• Works in almost every situation
19. .
.
concat
Public Domain http://commons.wikimedia.org/wiki/File:Adhesive_tapes_clear.JPG
20. .
CCoonnccaatt
• A "reference" puppet module:
puppetlabs/concat
• https://github.com/puppetlabs/puppetlabs-concat
• Provides definitions to manage file
• Alternative modules:
▶ onyxpoint/pupmod-concat
▶ theforeman/puppet-concat (fork of onyxpoint)
21. .
CCoonnccaatt??
• Concat takes a bunch of snippets
• Assemble them info a file
• Each snippet is a define
• The final file is a define
23. .
BBaassee aanndd ffrraaggmmeennttss
• Concat[] defines owner, ensure, mode of the
file
• Concat::Fragment[] defines the contents of
the file
• One Concat[] has multiple
Concat::Fragment[]
24. .
AAddvvaannttaaggeess ooff ccoonnccaatt
• More flexibility
▶ if
▶ virtual resource
▶ exported resources
▶ create_resources
• Mix templates and files
28. .
eexxeecc[[sseedd]] iiss bbrr00kkeenn
• Which options to pass to sed and grep?
• You should use as few Exec[] as possible
• grep ....
• Escape, regexes…
29. .
AAnnootthheerr aalltteerrnnaattiivvee:: ccoonnff..dd
• Some services support conf.d directories
• But it is hard to change existing parameters
• In which order are the files read?
• Don't forget to purge
30. .
.
Augeas
CC BY-SA 3.0 http://commons.wikimedia.org/wiki/File:Students_assisting_surgery.JPG
31. .
AAuuggeeaass
• Configuration editing tool
• First release in 2007
• API coded in C
• Command-line tools
• bindings for different languages
33. .
.
$ cat /etc/nsswitch.conf
# /etc/nsswitch.conf
##
Example configuration
#
passwd: db files
group: db files
initgroups: db [SUCCESS=continue] files
shadow: db files
gshadow: files
.
34. .
.
augtool> ls /files/etc/nsswitch.conf/
#comment[1] = /etc/nsswitch.conf
#comment[2] = Example configuration
database[1]/ = passwd
database[2]/ = group
database[3]/ = initgroups
database[4]/ = shadow
database[5]/ = gshadow
.
35. .
.
augtool> ls /files/etc/nsswitch.conf/database[1]/
service[1] = db
service[2] = files
.
36. .
NNaattiivvee ffoorrmmaatt -->> ttrreeee
• Augeas understand comments
• Augeas does not care about empty lines
• The cli tool (augtool) has autocomplete
• It recognize a lot of formats
37. .
.
augtool> set /files/etc/nsswitch.conf/database[1]/
service[last()+1] ldap
augtool> save
Saved 1 file(s)
.
38. .
.
$ cat /etc/nsswitch.conf
# /etc/nsswitch.conf
##
Example configuration
#
passwd: db files ldap
group: db files
initgroups: db [SUCCESS=continue] files
shadow: db files
gshadow: files
.
41. .
OOnnee AAPPII ttoo eeddiitt tthheemmaallll
• Can talk XML, ini, named, nginx, …
• Only change what is needed
• Ensure the syntax is right
42. .
AAuuggeeaass LLeennsseess
• Lenses are files that explain how to edit files
• It contains paths and syntax
• There are a lot of them available
• You can write your own lenses
43. .
”This brings the total number of lenses to
178. […] It’s depressing to think that
Linux/Unix systems have managed to grow
this many special snowflake formats.”
David Lutterkort, main developer
about Augeas 1.3.0
49. .
PPlluuggiinnssyynncc
• Puppet has pluginsync support for Augeas
• Drop your lenses in your modules
• lib/augeas/lenses
• Use the "lens" parameter of the augeas
resource
58. .
AAddvvaannttaaggeess
• Augeas is a mature tool
• Preserves comments in files
• It fails (if needed)
• Only changes what is needed
• A lot of lenses available
• Puppet integration
• Helpers available
59. .
FFiinnaall nnoottee
Most of the time, File[] resources are the way
to go. Augeas can help when you need to
change files generated by an application or
that you can not manage entirely.