Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
476 views
476 views

We're developing a provider for Puppet, but since there isn't much output it's very hard to debug when something doesn't work as expected. How can I improve the "debugability?"

in Scripting
by (100)
1 13 28
edit history

Please log in or register to answer this question.

1 Answer

0 votes
 

Puppet providers are notoriously difficult to debug. Sure, errors will be shown, and you'll get some debug output if you run puppet agent --test --debug. However, more often than not things will fail silently or the error message won't be indicative of the actual issue. Same goes for the debug output. Not to mention that Puppet agent debug output is very verbose.

Something that I see more or less frequently is that the debug output shows an external command being executed, but no indication that the execution of the command actually failed, or why.

What you can do is add some output statements to your provider code. Unfortunately this isn't very well documented, but the Puppet class provides several methods that can be used for this purpose (one for every log level listed here):

Puppet.debug("debug message")
Puppet.info("information message")
Puppet.notice("notice message")
Puppet.warning("warning message")
Puppet.err("error message")
Puppet.alert("alert message")
Puppet.emerg("emergency message")
Puppet.crit("critical message")

debug() messages are only shown when running puppet agent --test --debug, the others are displayed in the "regular" output (puppet agent --test).

A method in your provider could for instance look somewhat like this:

def enable
  begin
    Puppet.debug("enable resource")
    output = execute(['command', '--with', 'arguments'])
    Puppet.notice(output) unless output.nil?
  rescue Puppet::ExecutionFailure => e
    Puppet.err("#{__method__}: #{e.inspect}")
  end
end
by (100)
1 13 28
edit history
...