Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Puppet 5 Cookbook
  • Toc
  • feedback
Puppet 5 Cookbook

Puppet 5 Cookbook

By : Thomas Uphill
3.7 (3)
close
Puppet 5 Cookbook

Puppet 5 Cookbook

3.7 (3)
By: Thomas Uphill

Overview of this book

Puppet is a configuration management system that automates all your IT configurations, giving you control of managing each node. Puppet 5 Cookbook will take you through Puppet's latest and most advanced features, including Docker containers, Hiera, and AWS Cloud Orchestration. Updated with the latest advancements and best practices, this book delves into various aspects of writing good Puppet code, which includes using Puppet community style, checking your manifests with puppet-lint, and learning community best practices with an emphasis on real-world implementation. You will learn to set up, install, and create your first manifests with version control, and also learn about various sysadmin tasks, including managing configuration files, using Augeas, and generating files from snippets and templates. As the book progresses, you'll explore virtual resources and use Puppet's resource scheduling and auditing features. In the concluding chapters, you'll walk through managing applications and writing your own resource types, providers, and external node classifiers. By the end of this book, you will have learned to report, log, and debug your system.
Table of Contents (12 chapters)
close

Checking your manifests with puppet-lint

The Puppet official style guide outlines a number of style conventions for Puppet code, some of which we've touched on in the preceding section. For example, according to the style guide, manifests:

  • Must use two-space soft tabs
  • Must not use literal tab characters
  • Must not contain trailing white space
  • Should not exceed an 80-character line width
  • Should align parameter arrows (=>) within blocks

Following the style guide will make sure that your Puppet code is easy to read and maintain, and if you're planning to release your code to the public, style compliance is essential.

The puppet-lint tool will automatically check your code against the style guide. The next section explains how to use it.

Getting ready

Here's what you need to do to install puppet-lint:

  1. We'll install Puppet-lint using the gem provider because the gem version is much more up to date than the APT or RPM packages available. Create a puppet-lint.pp manifest as shown in the following code snippet:
package {'puppet-lint':
ensure => 'installed',
provider => 'gem'
}
  1. Run puppet apply on the puppet-lint.pp manifest, as shown in the following command:
t@cookbook:manifests$ puppet apply puppet-lint.pp
Notice: Compiled catalog for cookbook.example.com in environment production in 1.04 seconds
Notice: /Stage[main]/Main/Package[puppet-lint]/ensure: created
Notice: Applied catalog in 0.93 seconds

How to do it...

Follow these steps to use Puppet-lint:

  1. Choose a Puppet manifest file that you want to check with Puppet-lint, and run the following command:
t@cookbook:manifests$ puppet-lint puppet-lint.pp
WARNING: indentation of => is not properly aligned (expected in column 12, but found it in column 10) on line 2
ERROR: trailing whitespace found on line 4
  1. As you can see, Puppet-lint found a number of problems with the manifest file. Correct the errors, save the file, and rerun Puppet-lint to check that all is well. If successful, you'll see no output:
t@cookbook:manifests$ puppet-lint puppet-lint.pp
t@cookbook:manifests$

There's more...

Should you follow Puppet style guide and, by extension, keep your code lint-clean? It's up to you, but here are a couple of things to think about:

  • It makes sense to use some style conventions, especially when you're working collaboratively on code. Unless you and your colleagues can agree on standards for whitespace, tabs, quoting, alignment, and so on, your code will be messy and difficult to read or maintain.
  • If you're choosing a set of style conventions to follow, the logical choice would be those issued by Puppet and adopted by the community for use in public modules.

Having said that, it's possible to tell Puppet-lint to ignore certain checks if you've chosen not to adopt them in your code base. For example, if you don't want puppet-lint to warn you about code lines exceeding 80 characters, you can run puppet-lint with the following option:

puppet-lint --no-80chars-check

Most developers have terminals with more than 80 characters now; the check for 80 characters is generally disabled in favor of a new 140-character limit. You may disable the 140 character check with the following:

puppet-lint --no-140chars-check

Run puppet-lint --help to see the complete list of check configuration commands.

See also

  • You can find out more about Puppet-lint at https://github.com/rodjek/puppet-lint.

  • The Automatic syntax checking with Git hooks recipe in Chapter 2, Puppet Infrastructure

  • The Testing your manifests with rspec-puppet recipe in Chapter 9, External Tools and the Puppet Ecosystem
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete