Book Image

Puppet Cookbook - Third Edition

Book Image

Puppet Cookbook - Third Edition

Overview of this book

Table of Contents (17 chapters)
Puppet Cookbook Third Edition
About the Authors
About the Reviewers

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:

  1. Create a new greeting module as follows:

    class greeting {
      file { '/tmp/greeting':
        source => [ 'puppet:///modules/greeting/hello.txt',
  2. Create the file modules/greeting/files/hello.txt with the following contents:

    Hello, world.
  3. Create the file modules/greeting/files/universal.txt with the following contents:

    Bah-weep-Graaaaagnah wheep ni ni bong
  4. Add the class to a node:

    node cookbook {
      class {'greeting': }
  5. Run Puppet:

    [root@cookbook ~]# puppet agent -t
    Info: Caching catalog for cookbook...