A very simple Puppet module that concatenates multiple text parts together to one file. The single parts can be file sources, string content or existing files on the target system.
- Core utilities: find, sort, xargs
- dirname function, e.g. as provided by http://github.com/puzzle/puppet-common
- Tested on Puppet 0.25.4
First, define the file that should be concatenated from the parts:
The dir parameter specifies in which folder the parts are collected.
Then, define some parts:
The directory in the resource name of each part must match the dir parameter used in the concatfile resource, that is how Puppet knows they are connected. The files will later be sorted numerically and concatenated in that order.
The result is that the file /etc/sysctl.conf is concatenated from the 3 files in /etc/sysctl.conf.d/. Their content comes from 3 different possible sources: a Puppet files resource, a string and a symlink to a local file.
Each part is deployed as file in the specified folder. A simple exec command in the form of find ... | sort ... | cat ... > target_file is then used to concatenate all parts together. Apart from the basic update behavior from Puppet when any file is removed/modified, or any definition in the code is added/modified/removed, an update should also be triggered when a alien file is placed in the folder where the parts are stored, and the file gets removed.
Possible parameters to concatfile are:
- dir (required)
Possible parameters to concatfile::part are:
Only one of source, content or file makes sense and is allowed.
The defines can easily be wrapped to save some typing or e.g. introduce an order parameter:
- Triggering the update when the concatenated file is modified was not tested (did not have a puppet master around, and remembering checksums does not work completely with Puppet in standalone mode).
Anselm Strauss http://github.com/amsibamsi
- DavidSchmitt/common (1.0.0)