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Â
modules/greeting/files/hello.txt
 file with the following content:
Hello, world.
- Create theÂ
modules/greeting/files/universal.txt
 file with the following content:
Bah-weep-Graaaaagnah wheep ni ni bong
- Add the class to a node:
node cookbook { class {'greeting': } }
- Run Puppet:
[root@cookbook ~]# puppet agent -t ... Notice: /Stage[main]/Greeting...