Book Image

Troubleshooting Puppet

By : Thomas Uphill
Book Image

Troubleshooting Puppet

By: Thomas Uphill

Overview of this book

Table of Contents (14 chapters)

Writing code


The Puppet style guide (for more information, visit https://docs.puppetlabs.com/guides/style_guide.html) was developed to define a common way of writing code that reduces errors. The style guide makes several suggestions to make your code more readable and consistent.

A common syntax error is to forget a comma between the attributes of a resource. Consider the following code:

file { '/tmp/oops':
mode    => '0644',
owner   => '0',
group   => '0'
content => 'Forgot something.'
}

In the preceding example, a comma is missing. Because of this, the catalog will fail to compile and show the following error:

Error: Could not parse for environment production: Syntax error at 'content'; expected '}' at oops.pp:5 on node trouble.example.com

This type of simple syntax error can be avoided by putting a comma at the end of every attribute, regardless of whether it is the final attribute or not. An advantage of this is that you can move attributes around within the definition and...