Before we start, please read the following questions and answers as a primer to discover why I built this tool and how it can help solve puppet development problems.
A debugger is a tool present in almost all programming languages that allows you to see how the compiler evaluates your code as if you were standing inside the compiler with a poking stick.
Many debuggers and REPLs can be found online
Examples of other existing debuggers or REPLs.
Puppet code can become quite complex when using some of the advanced functionality found inside the Puppet language. Additionally, Puppet code is used across multiple devops tools like Bolt so it makes sense to have a way to debug Puppet code when a unit test is not possible or feasible.
Below are just a few reasons why you would use a debugger:
Puppet Debugger is not a replacement for proper unit testing. Unit testing is used to catch errors across code changes while a debugger does not. However, Puppet Debugger can be used to to evaluate complex code where you might have used a unit test before to dump output to STDOUT.
Using Puppet’s traditional debugging methods is inefficient when compared to a live interactive console. Puppet Debugger replaces these archaic methods:
Puppet Debugger will show you the before, during, and after state, while other tools show the before and after state only.
Puppet Debugger was designed to run on all major platforms. Only requirement is a modern ruby installation.
ANY PUPPET CODE. ANY.
Puppet apply has been the go-to method for evaluating code. However, it is slow and requires the usage of notify resources or other functions to dump values to STDOUT. Puppet Debugger offers:
=> Evaluation Error: Error while evaluating a Function Call,
Could not find class ::<insert name of class> for foo.example.com
(file: /tmp/puppet_debugger_input20200421-14380-1b48jnn.pp, line: 1, column: 1)
The following error is a result of the class not being in your modulepath.
When puppet compiles the catalog it searches the modulepath you provided it to find
the classes. You can provide the modulepath in many ways but the simplest
is via the --basemodulepath
option.
puppet debugger --basemodulepath=/path/to/modules
# This must be a directory of modules.
puppet debugger --basemodulepath=spec/fixtures/modules
# use when inside a module with fixtures