Puppet 3.7 File Function Improvements
Puppet’s always had a couple of little inconsistencies when it comes to the file and template functions. The file function has always been able to search for multiple files and return the contents of the first file found but it required absolute paths. The template function accepts module based paths but doesn’t allow for matching on the first found file. Although this can be fixed with the Puppet Multiple Template Source Function.
One of the little niceties that came with Puppet 3.7 is an easily missed
improvement to the file
function that makes using it
easier and more consistent with the template function. In earlier puppet
versions you called file with absolute paths, like this:
file { '/tmp/fakefile':
content => file('/etc/puppet/modules/yourmodulename/files/fakefile')
}
Thanks to a code submission from Daniel
Thornton (which fixes an issue that’s been logged since at least
2009) you can now call the file function in the same way as you’d
use template
, while retaining support for matching the first
found file.
file { '/tmp/fakefile':
content => file('yourmodulename/fakefile')
}
# or
file { '/tmp/fakefile':
content => file("yourmodulename/fakefile.${::hostname}", 'yourmodulename/fakefile')
}
Although most puppet releases come with a couple of ‘wow’ features sometimes it’s the little ones like this that adds consistency to the platform and helps cleanup and abstract your modules, that you appreciate more in the long term.