Using multiple file sources
A neat feature of Puppet's file
resource is that you can specify multiple values for the source
parameter. Puppet will search them in order. If the first source isn't found, it moves on to the next, and so on. You can use this to specify a default substitute if the particular file isn't present, or even a series of increasingly generic substitutes.
How to do it...
This example demonstrates using multiple file sources:
Create a new greeting module as follows:
class greeting { file { '/tmp/greeting': source => [ 'puppet:///modules/greeting/hello.txt', 'puppet:///modules/greeting/universal.txt'], } }
Create the file
modules/greeting/files/hello.txt
with the following contents:Hello, world.
Create the file
modules/greeting/files/universal.txt
with the following contents:Bah-weep-Graaaaagnah wheep ni ni bong
Add the class to a node:
node cookbook { class {'greeting': } }
Run Puppet:
[root@cookbook ~]# puppet agent -t Info: Caching catalog for cookbook...