Ask Your Question
4

How do I debug custom functions?

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

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
4

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

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

Comments

This doesn't seem to output anything.

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

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 -0500 )edit
2

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

AronR gravatar image

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

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 = Logger.new(STDOUT)
    log.level = Logger::INFO

    myvar='foo'
    # 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 ...
    log.info("myvar ...
(more)
edit flag offensive delete link more

Comments

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 -0500 )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 -0500 )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 -0500 )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 -0500 )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 -0500 )edit
0

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

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 File.open('/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

Comments

function_notice does not seem to work

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

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

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

Comments

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 -0500 )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 -0500 )edit

https://gist.github.com/robrwo/37a0f4c773b06cabf476

robrwo gravatar imagerobrwo ( 2013-10-14 11:31:38 -0500 )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

3 followers

Stats

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

Seen: 6,100 times

Last updated: Feb 25 '14