Paul Chernoch
Paul Chernoch

Reputation: 5553

Can a custom Ruby function defined in one Puppet module be called from a .pp file in another module?

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/

Upvotes: 2

Views: 1211

Answers (2)

ptierno
ptierno

Reputation: 10074

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

Upvotes: 0

Felix Frank
Felix Frank

Reputation: 8223

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.

Upvotes: 3

Related Questions