Own puppet function

I'm trying to make my own function. I keep getting this message.

err: Could not retrieve catalog from remote server: Error 400 on SERVER: Function 'brent_k' does not return a value at /etc/puppet/modules/munin/manifests/init.pp:17 on node XYZ.com

Here is my simple code

xyz.com:/etc/puppet/modules/munin/lib/puppet/parser/functions# cat brent_k.rb
  module Puppet::Parser::Functions
    newfunction(:brent_k, :type => :rvalue) do |args|
      val = 'ok'
      val
    end
  end

And then in my manifest, I have

$a = brent_k()

I tried return val too. How can I fix this?


Solution 1:

When you change any custom ruby code, such as a custom function, you must restart the Puppetmaster. If you are running puppet under passenger, this means restarting Apache. Otherwise, you'll get the old version.

In addition, there is a rather nasty bug that kicks in if you are hosting multiple environments in your puppetmaster with an identically named function in the other environment. In this case, you have no way to be sure which environment's function is used when you call the function name! It uses the same function namespace across all environments... (this is confirmed to happen in Puppet 2.7.22, not sure about 3.x)