How do you use the source keyword in Puppet’s DSL (when writing a manifest)?

When writing a Puppet manifest you can use the "content" reserved word.  You then have quotes around the actual text content of this file right in the manifest itself.  This works for a file that you want to create on a Puppet Agent server as long as the content is roughly one line of text.  But for a binary file, this will not work (as it cannot appear in the manifest).  The "source" reserved word allows you to point to a specific file on the Puppet Master server.  The Puppet constructor has three slashes after the colon.  Here is an example of the "source" reserved word and the Puppet constructor:

source => puppet:///modules/goodFolder/

What is important to know is the following non-obvious facts.  

1) The corresponding goodFolder must actually have a subdirectory named "files."  This directory "files" is not explicit in the source field declaration.  

2) Puppet.conf must have a main section that tells Puppet where to look for the "modules" subdirectory.  

default_modules = /etc/puppet/modules/

3) The path to the modules including the subdirectories (named goodFolder in this example and files itself) must have permissions that allow the Puppet process to access them.  This is true of the file too.

4) Some subdirectory besides "files" must be in "modules" to house "files."  The goodFolder in the example satisfies this.

Once you know these four facts, you can use the valuable source reserved word.  On a final note, if the destination of the file in the manifest is configured for a heterogeneous operating system relative to the Puppet Master OS (e.g., c:/temp/ is the destination of the manifest file transfer yet the Puppet Master is running on Linux or the destination is /tmp/ and the Puppet Master server is running on Windows), you may get an ignorable error when you compile the manifest.  But this is only true if your manifest doesn't specify nodes or classes to ensure Puppet does not attempt to apply a manifest for a non-applicable OS.  The caching of the catalog will find that the path "must" be fully qualified when it compiles.  Compilation will be successful and the manifest will run when the Puppet Agents connect.  So don't be surprised when this ignorable message is displayed.

Update on 12/28/16:  For troubleshooting manifests that are not doing what you expect despite no messages or few errors in the logs, see this posting.

Leave a comment

Your email address will not be published. Required fields are marked *