On 24/08/17 04:27, John Baird wrote:
Henrik,

Thanks for the feedback, while I wish there was a "better/native" way, I have accepted that I need to write my own function.  I would like to be able to use a similar syntax as "lookup()" and simply specify a filepath and have the contents returned as the content of the file being created.  I am fairly certain I can accomplish this, but I am not sure how I gain access to the hiera scope or hierarchy that is defined by either the module or the global/environment scope.  I want my custom module to be able to search the hiera path(s) for the necessary file structure.  How would I go about getting that scope into a custom function?  Thanks!


Unless you are using the bad practice of using 'calling_module' or even worse: variables in the calling scope (if you managed to get that working) - you do not need to relay the *calling* scope. If all you are accessing in your hiera.yaml is top scope variables, then you can just use 'call_function' (or in puppet language, just call it with normal puppet syntax).

If you however must delegate *calling* scope, then this is an example of a Ruby function that does that: https://github.com/puppetlabs/puppet/blob/ebd96213cab43bb2a8071b7ac0206c3ed0be8e58/lib/puppet/functions/include.rb

You cannot do the same with a function written in the puppet language.
(FWIW: In general it is a really bad idea to design functions that do different things depending on from where they are called).

When you write such a delegating function, you can call another function and pass in the scope to use by using 'internal_call_function' instead of 'call_function' - the signature is the same but it takes a scope as its first argument.

Best,
- henrik

--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/onm42t%246eu%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to