2
votes

I have a custom function that I need to call (server-side) from at least two different puppet modules. The calls are to be made in Puppet DSL defined types, not Ruby-based custom types and providers.

I know that if I put the definition in a .rb file in the "lib\puppet\parser\functions" directory it is accessible in that module. Can that function be called from other modules, perhaps with some module qualifier before it? Or do I need to use some other approach? The function accepts two string arguments and returns a hash.

The little that I know about custom functions is found here:

https://docs.puppetlabs.com/guides/custom_functions.html

https://docs.puppetlabs.com/guides/plugins_in_modules.html

The following blog post seems to suggest that all functions from all modules are accessible from any module, but I may be misunderstanding it:

http://www.masterzen.fr/2011/10/29/puppet-extension-points-part-1/

2
as long as pluginsync is enabled, your function should be available to any other manifest. - ptierno
Thank you. If you put this as the answer and include a link to a Puppet labs doc that clarifies this, I will accept it as the answer. - Paul Chernoch
@ptierno pluginsync is relevant for the agent only. It is unrelated to parser functions. It will sync them to the agent, but manifests can be compiled regardless of that, even when pluginsync is disabled (don't do that, though). - Felix Frank
@FelixFrank Thanks for that. I am considering the master as an agent node also i this case. docs.puppetlabs.com/guides/plugins_in_modules.html pretty much states that pluginsync should add the custom function to the proper $libdir on the master. Probably should have been more specific. - ptierno
Yes, turns out it's from early 2010, from before Puppet version 2.6.0. I will try and have it removed, it's incorrect and misleading. - Felix Frank

2 Answers

0
votes

If you have pluginsync enabled, puppet will make available all of your custom facts, types, functions, etc.

In puppet.conf set pluginsync=true

Reference

Plugins in modules

3
votes

Plugins in modules are always available to the compiler, in any manifest, encompassing all modules. This is true for both types and parser functions.

For example, the stdlib module includes the file_line type, which is expressly there for use outside of the module.