On 2016-01-02 24:23, Martin Alfke wrote:
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.
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.
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).
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.