Re: [Puppet-dev] Puppet 4: defined resource types and epp template

2016-02-04 Thread Martin Alfke

On 01 Feb 2016, at 19:15, Henrik Lindberg  
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 example just switches from template() to epp() function.
According to your writing you must pass all parameters to the epp() function.

> 
> 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.
This especially feels bad, when we will have performance improvement for epp in 
the future.

I need to rethink whether inline_epp() is the proper replacement for template() 
function.


> This design makes the code more maintainable and templates more reusable. It 
> is also easier to test the templates (there is a command line utility (puppet 
> epp IIRC) that allows you to feed values into a templates and render the 
> result).
> 
> Hope that helps
> - henrik
> 
>> 
>> Best,
>> Martin
>> 
> 
> 
> -- 
> 
> 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 puppet-dev+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-dev/n8o7b5%24k5j%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 puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/E26F3ED6-17F6-47FA-A215-2463253858ED%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet-dev] Puppet 4: defined resource types and epp template

2016-02-04 Thread Martin Alfke

On 04 Feb 2016, at 14:30, Henrik Lindberg  
wrote:

> On 2016-04-02 11:46, Martin Alfke wrote:
>> 
>> On 01 Feb 2016, at 19:15, Henrik Lindberg  
>> 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 puppet-dev+unsubscr...@googlegroups.com.
> 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 puppet-dev+unsubscr...@googlegroups.com.
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.


[Puppet-dev] Puppet 4: defined resource types and epp template

2016-01-31 Thread Martin Alfke
Hi,

I recently had an issue with epp template within a defined resource type.
Let’s assume the following code snippets:

# modules/test/manifests/init.pp
class test {
  ::test::files { 'test':
param1 => 'value',
  }
}

# modules/test/manifests/files.pp
define test::files (
  $param1 = '',
){
  file { "/tmp/${title}":
ensure  => file,
content => epp('test/files.epp'),
  }
}

# modules/test/templates/files.epp
<%= $param1 %>

The parameter Param1 will not get the data provided within define declaration.

Is this desired behaviour?
Should I open a bug?
Is this a known bug?

When passing the param1 data via hash to epp function, data will get added to 
the template.

Best,
Martin

-- 
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 puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/1672269B-ADC4-4CFB-9D82-331FEC337F24%40gmail.com.
For more options, visit https://groups.google.com/d/optout.