Ask Your Question

How do I debug custom functions?

asked 2013-10-11 10:06:56 -0600

robrwo gravatar image

I've written a custom Puppet function in Ruby.

The function works when called used in site.pp, but not when used in any modules.

How do I debug these functions? Is there a way for them to putput diagnostic or debug information?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2014-02-25 17:24:50 -0600

Stefan gravatar image

Inside your custom function you can use info("some_info)", warning("some_warning") or debug("some_debug") to use the puppet logging function. But be aware that functions are executed on your puppet master, so the log messages will also be logged on your puppet master.

edit flag offensive delete link more


This doesn't seem to output anything.

robrwo gravatar imagerobrwo ( 2014-03-07 08:37:37 -0600 )edit

You have checked on your puppet master? Depending on where you are logging stuff you'll probably find the output in `/var/log/messages`. Also be aware that when you ...(more)

Stefan gravatar imageStefan ( 2014-03-07 12:13:30 -0600 )edit

answered 2014-01-30 18:43:24 -0600

AronR gravatar image

updated 2014-02-13 22:03:26 -0600

One option might be to experiment with using Ruby's simple, integral Logger class to emit log statements; e.g. something akin to this. (The exact code block below is off the top of my head and untried by me, but follows a pattern I've used elsewhere):

require 'logger'  
module Puppet::Parser::Functions
  newfunction(:yourfunctionname, :type => :rvalue)
  do |args|

    log =
    log.level = Logger::INFO

    # Yes, it makes little sense to log a value just before returning it,
    # since you'll have access to it anyway, but this is just an example ..."myvar ...
edit flag offensive delete link more


Another potential issue might be the module (or modules) in which your custom function is present; I'm unclear about whether it's possible to invoke a custom function in ...(more)

AronR gravatar imageAronR ( 2014-01-30 20:00:11 -0600 )edit

it basically does not matter in which module you put your custom functions, they can be used everywhere.

Stefan gravatar imageStefan ( 2014-02-25 17:27:14 -0600 )edit

This dosn't work. It does not output anything when I run "puppet agent -t"

robrwo gravatar imagerobrwo ( 2014-03-07 08:22:56 -0600 )edit

Thanks, Stefan, for that information about access to custom functions across modules - it's much appreciated, as are many of your posts and comments here - I've learned a lot ...(more)

AronR gravatar imageAronR ( 2014-03-07 11:22:25 -0600 )edit

@robrwo: It does not output anything when you run `puppet agent -t` because functions are always run on your puppet master when your master compiles the catalog for your node ...(more)

Stefan gravatar imageStefan ( 2014-03-07 13:28:34 -0600 )edit

answered 2014-02-01 05:03:48 -0600

spend gravatar image

Try: function_notice(["Desired is: '#{desired}' "])

or if like me you prefer to write debugging to file then these tend to work'/tmp/myhierapath.log', 'a'){|f| f.print "\nhierarchy:" ; f.write(hierarchy) ;f.print "\n" }

The file method I find better since you don't lose sight of info in logs, and it is together sequentially when you require several debug lines to trace states.

edit flag offensive delete link more


function_notice does not seem to work

robrwo gravatar imagerobrwo ( 2014-03-07 08:25:24 -0600 )edit

answered 2013-10-12 09:40:07 -0600

bmurts gravatar image

Use puppet agent -td and puppet agent -td --trace to get more detailed output to help debug.

edit flag offensive delete link more


I've already tried this. It does not give any output about the function at all.

robrwo gravatar imagerobrwo ( 2013-10-14 06:51:56 -0600 )edit

Can you gist your code for the custom function & how it's being used in a module? Please include any errors or warning output from the Puppet runs as well.

bmurts gravatar imagebmurts ( 2013-10-14 07:29:41 -0600 )edit

robrwo gravatar imagerobrwo ( 2013-10-14 11:31:38 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2013-10-11 10:06:56 -0600

Seen: 8,146 times

Last updated: Feb 25 '14