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:
Modify your
manifests/nodes.pp
file as follows:node 'cookbook' { file { '/tmp/greeting': source => [ 'puppet:///modules/admin/hello.txt', 'puppet:///modules/admin/generic.txt'], } }
Create the file
modules/admin/files/hello.txt
with the following contents:Hello, world.
Create the file
modules/admin/files/generic.txt
with the following contents:All-purpose greeting, sentient beings.
Run Puppet:
ubuntu@cookbook:~/puppet$ papply Notice: /Stage[main]//Node[cookbook]/File[/tmp/greeting]/ensure: defined content as '{md5}54098b367d2e87b078671fad4afb9dbb...