A collection of task oriented solutions in Puppet

 

Adding debug messages to your manifests

Challenge

You want to add some debug messages to puppet so you can see what's happening in your manifests.

Solution

class debugging {

  # for debug output on the puppet master
  notice("Running with \$mysql_server_id ${::mysql_server_id} ID defined")

  # for debug output on the puppet client
  notify {"Running with \$mysql_server_id ${::mysql_server_id} ID defined":}

  # for debug output on the puppet client - with full source information
  notify {"Running with \$mysql_server_id ${::mysql_server_id} ID defined":
    withpath => true,
  }

}

Explanation

Sometimes you need to double check the value of a fact or variable at a given point or even just output a short message to show what puppet is doing. Puppet provides a number of ways to do this and the simplest is by using the notice function if you want the message to appear on the puppet master or the notify type if you want the message displayed on the client. These messages are written to the log when puppet runs and can also be seen in the output of a debug run.

The addition of the withpath attribute to a notify resource causes it to print the full resource path with the message.

notify { 'Hello World': }
# Notice: Hello World

notify { 'Hello World': withpath => true }
# Notice: /Stage[main]/Main/Notify[Hello World]/message: Hello World

The last common variant is using a separate title and message:

class debug_with_path {

  notify { 'FqdnTest':
    withpath => true,
    name     => "my fqdn is ${::fqdn}",
  }

}
# notice: /Stage[main]/Not::Base/Notify[FqdnTest]/message: my fqdn is pcbtest.udlabs.private