On 04 Feb 2016, at 14:30, Henrik Lindberg <[email protected]> wrote:
> On 2016-04-02 11:46, Martin Alfke wrote: >> >> On 01 Feb 2016, at 19:15, Henrik Lindberg <[email protected]> >> wrote: >> >>> >>> That is exactly what you should do. An external (file based epp) when >>> called, does not get to see variables in the scope from which it was >>> called/used. This design is deliberate. Think of the template as a function >>> you are calling, and you have to give it its arguments. >> >> In this case the documentation on the website is wrong: >> https://docs.puppetlabs.com/puppet/latest/reference/lang_template_epp.html#example-template >> > The long example is wrong in that it does not show that arguments must be > given in a hash. > > The documetation for epp has unfortunately been boiled down to just the bare > minimum and the important distinction that variables must be given has been > lost in the series of rewrites that were made. > > The implementation clearly restricts epp() to only see global scope. > > The specification is also clear about scoping: > https://github.com/puppetlabs/puppet-specifications/blob/master/language/templates.md#visibility-of-scoped-variables Yes. the written description is clear about that. > > I filed a documentation ticket. > >> The example just switches from template() to epp() function. >> According to your writing you must pass all parameters to the epp() function. >> > > yes, epp() requires that arguments are given in the call. epp() templates > only have access to global variables (i.e. $::osfamily and such). > > >>> >>> Contrast this with the inline_epp, which you can think of as a >>> lambda/code-block. Here the code block gets to see the variables in scope, >>> since it is itself in that scope (part of the same piece of code). >>> >> Got it. >> To be honest: this is ugly. >> I always thought of epp() being a full replacement for template() without >> the scope issue. > > The ERB based template() function is for templates in files. The epp() > function is also for files. The big difference between them is that all > variables used by the template processed by epp() must be given to the > function. > > The inline_epp() may in the special case, when it does not declare parameters > have access to all variables in scope. This was deemed to be harmless as all > of the logic is in one place, and there is never a question of reuse. It is > also seen as an easy way to transition to inline_epp() from inline_template(). > > With that, I am not sure I understand your comments. What is it that you > think is ugly? > >> This especially feels bad, when we will have performance improvement for epp >> in the future. >> > > I have not seen tickets with reports of performance problems. How bad is it? You mentioned it somewhere at PuppetConf that in the future the epp() function will have a performance benefit over template() function due to template() needing the ruby stack whereas epp() is running in the java based parser (as far as I have understood this). > > 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 Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-dev/n8vjpn%244u0%241%40ger.gmane.org. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/F7162FAD-4521-4CAF-AEA3-B39F87AA4EAD%40gmail.com. For more options, visit https://groups.google.com/d/optout.
