Forge Home

debug

Used for starting the puppet debugger from inside puppet code

11,835 downloads

2,344 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 0.2.0 (latest)
  • 0.1.3
  • 0.1.1
  • 0.1.0
released Jul 1st 2020
This version is compatible with:
  • Puppet Enterprise 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2016.4.x
  • Puppet >= 4.10.0 < 7.0.0
  • , , , , , ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'nwops-debug', '0.2.0'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add nwops-debug
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install nwops-debug --version 0.2.0

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

nwops/debug — version 0.2.0 Jul 1st 2020

Build Status

Puppet Debug

This module contains a function called debug::break() and is for use with the puppet-debugger gem.

The function is used for starting the puppet debugger from inside the puppet code.

Why is this important? Puppet code is getting more complex and in order to understand the code you need to get inside the compiler look around at the variables, scope and available functions.

The debugger is extremely helpful in understanding the puppet language and your puppet code. Think ruby pry but for puppet code.

The function will inject the scope, node and environment data into the debugger allowing you to poke around to see variables, functions, facts, classes, and resources defined in the current scope.

Requirements

Ensure you have installed the puppet-debugger gem gem install puppet-debugger or place this in your Gemfile gem 'puppet-debugger', '>= 0.4' for your puppet module.

This also requires puppet 3.8+ with future parser enabled.

You will also want to include this module in your fixtures file if using for rspec-puppet unit testing.

debug:
   repo: https://github.com/nwops/puppet-debug

Usage

DO NOT RUN THIS ON YOUR PUPPET SERVER OR IN PRODUCTION

Planes will fall out of the sky, and kittens will die. Do you really want that? Although there is a safety mechanism to prevent the this function from being called under a daemonized puppet run so it is not all that bad.

In order to start the puppet-debugger from within code just place the debug::break() function inside your manifest code where you want the scope to be injected. This will automatically call the debugger whereami command and show where in the code the debug::break() function was called from. This makes it obvious where in the code you are evaluating from. This gives you the ability to step through your code. To goto the next iteration just use the exit command and the compiler will continue to compile where it previously left of.

You can access variables just as you would when writing puppet code. So once inside the debugger session type $some_var_name

Example:

class debugger::debugger_test(
  $var1 = 'value1',
  $var2 = ['value1', 'value2', 'value3']
)
{
  # dummy resources so we can show list of resources
  file{'/tmp/test.txt': ensure => present, mode => '0755'}
  service{'httpd': ensure => running}

  # how to find values with an empheral scope
  $var2.each | String $item | {
    file{"/tmp/${item}": ensure => present}
    debug::break({'run_once' => true})
  }
  debug::break({'run_once' => true})
  if $var1 == 'value1' {
    debug::break({'run_once' => true})
  }
}

Example Debugger session when inside the each block. Notice the item variable.

Ruby Version: 2.3.1
Puppet Version: 4.7.0
Puppet Debugger Version: 0.4.0
Created by: NWOps <corey@nwops.io>
Type "exit", "functions", "vars", "krt", "whereami", "facts", "resources", "classes",
     "play", "classification", "reset", or "help" for more information.

          8:   service{'httpd': ensure => running}
          9:
         10:   # how to find values with an empheral scope
         11:   $var2.each | String $item | {
         12:     file{"/tmp/${item}": ensure => present}
      => 13:     debug::break({'run_once' => false})
         14:   }
         15:   debug::break({'run_once' => false})
         16:   if $var1 == 'value1' {
         17:     debug::break({'run_once' => false})
         18:   }
1:>> $item
 => "value1"
>>

If using with rspec-puppet, only the facts you define in your test suite will be present in the debugger.

For more information on how to use the puppet debugger please refer to the documentation

Troubleshooting

This module and puppet-debugger gem are very new, there will be bugs. Please file them at puppet-debugger gem.