Using Augeas to automatically edit config files
Sometimes it seems like every application has its own subtly different config file format, and writing regular expressions to parse and modify all of them can be a tiresome business.
Thankfully, Augeas is here to help. Augeas is a system that aims to simplify working with different config file formats by presenting them all as a simple tree of values. Puppet's Augeas support allows you to create augeas
resources that can make the required config changes intelligently and automatically.
How to do it…
Follow these steps to create an example augeas
resource:
Modify your
manifests/nodes.pp
file as follows:node 'cookbook' { augeas { 'enable-ip-forwarding': context => '/files/etc/sysctl.conf', changes => ['set net.ipv4.ip_forward 1'], } }
Run Puppet:
ubuntu@cookbook:~/puppet$ papply Notice: /Stage[main]//Node[cookbook]/Augeas[enable-ip-forwarding]/returns: executed successfully Notice: Finished catalog run in 0.55 seconds
Check that...