Testing code

When writing code, mistakes are bound to happen. There are several layers to troubleshooting the problems that will occur. In the next three sections, we'll look at some solutions to problems with your code, starting with the simplest layer to fix—the syntax.

Validating code

The puppet-lint tool is good at finding problems with style and certain syntax issues. For real syntax problems, Puppet has a built-in validation mode, puppet parser validate. To validate your code, run puppet parser validate against your manifest.

For example, the following manifest (validate.pp) has a syntax error that is easy to make:

 1 class validate 2 ( 3 $who = "Me", 4 $where = "Here", 5 ) { 6 file { 'why': 7 path => '/tmp/why' 8 contents => "Por Que Dos?\n", ...

Get Troubleshooting Puppet now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.