Chapter 3. Coding Practices

In this chapter, we look at best practices related to using the Puppet language. This chapter focuses predominantly on Puppet’s conditional logic, operators, function calls, and data structures. We concentrate on resource types and classes at a high level so that we can delve deeper on those subjects in Chapter 4 when we discuss module design, and Chapter 5 when we explore best practices relating to a number of common resource types, and Chapter 7 when we look at code organization and intermodule relationships.

The Style Guide

We advise you to review the Puppet language style guide, which covers recommended usage and what validation and testing tools to expect. We do not repeat the style guide in this chapter; instead, we expand upon the information Puppet provides in the guide, emphasizing a few key and often overlooked aspects of the guide.

The Puppet style guide focuses on keeping code clear and easy to understand, as well as maintaining a clean revision history. A major benefit of the official style guide is that development and testing tools automatically identify and correct violations of the guide.

The Puppet style guide is now updated for each version of Puppet. Always refer to the version you are coding for, like so:

Be aware that the style guide often contains recommendations made to ensure backward compatibility with older Puppet ...

Get Puppet Best Practices now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.