custom puppet parser functions does not get re-executed on subsequent puppet agent runs.

asked 2018-06-15 08:06:17 -0600


I want to write a custom function using legacy parser function API of puppet. Because I want to support it on puppet 3. Here is my function: endmodule Puppet::Parser::Functions newfunction(:testt, :arity =>1, :type => :rvalue, :doc => "Convert input array of hashes (optionally JSON encoded) to a puppet Array of JSON encoded Strings") do |arg| tvault_ip = arg[0] return "1234" end

When I run puppet agent -t on agent node, I get correct value i.e 1234. But If I change this value in function to something else like "456 " and run puppet agent -t again, it's still returning 1234 Strange. Looks like function is not getting re-executed on next runs. It is returning old value only.

Any idea?

Thanks Shyam

edit retag flag offensive close merge delete


Are you sure the updated function is being loaded?

supercow gravatar imagesupercow ( 2018-06-16 13:36:43 -0600 )edit

It is getting executed for first time correctly, I think it means function is getting loaded. Any special configuration we need to do to make it load on every run? gravatar ( 2018-06-18 00:59:40 -0600 )edit

When you run a custom function, it is cached until you restart the puppet service. After a service restart, you'll start seeing the right value... it makes iteration difficult, and I was previously struck by this same bug. (correct value with my_functio.rb, but my_function.rb shows the old value)

DarylW gravatar imageDarylW ( 2018-06-18 08:28:18 -0600 )edit

This is due to the way that puppet internally stores the functions for ruby to access them. You also can have a function 'bleed' over from a different environment under puppet 3, and it wasn't until later in puppt 4 that they added a way for them to be hashed differently based on environment

DarylW gravatar imageDarylW ( 2018-06-18 08:29:12 -0600 )edit

If you throw the 1234 value into hiera does it solve the issue ?

x099008 gravatar imagex099008 ( 2018-06-18 12:54:58 -0600 )edit