Building config files using snippets
Sometimes you can't deploy a whole config file in one piece, yet making line-by-line edits isn't enough. Often, you need to build up a config file from various bits of configuration managed by different classes. For example, you might have two or three services which require rsync
modules to be configured, so you can't distribute a single rsyncd.conf
file. In this situation, you can use a snippet approach: write several separate snippets or fragments which are then concatenated into a single file.
How to do it…
Here's an example of building a config file using the snippet pattern:
Create the file
modules/admin/manifests/rsyncdconf.pp
with the following contents:class admin::rsyncdconf { file { '/etc/rsyncd.d': ensure => directory, } exec { 'update-rsyncd.conf': command => '/bin/cat /etc/rsyncd.d/*.conf > /etc/rsyncd.conf', refreshonly => true, } }
Create the file
modules/admin/files/myapp.rsync
with the following contents...