The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com
https://tickets.puppetlabs.com. See the following page for information on filing tickets with JIRA:
Can't access a lambda variable in a template (Future Parser)
|Affected Puppet version:||3.2.2||Branch:||https://github.com/puppetlabs/puppet/pull/1735|
|Keywords:||future parser scope template variable|
Ticket tracking is now hosted in JIRA: https://tickets.puppetlabs.com
<% @value %>
<%= scope.lookupvar('value') %>
#1 Updated by eric sorenson almost 3 years ago
- Status changed from Unreviewed to Investigating
- Assignee set to Henrik Lindberg
Henrik — I confirmed this but I’m not sure whether it’s intentional or not. The docs say:
When a lambda is evaluated, this takes place in a local scope that shadows outer scopes. Each invocation of a lambda sets up a fresh local scope. The variables assigned (and the lambda parameters) are immutable once assigned, and they can not be referenced from code outside of the lambda block. The lambda block may however use variables visible in the scope where the lambda is given, as in this example...
But in this case, the template access is inside the lambda block.
I have a minimalistic reproduction case here: Gist 5881061
#3 Updated by Henrik Lindberg almost 3 years ago
- Status changed from Investigating to In Topic Branch Pending Review
- Keywords changed from future parser to future parser scope template variable
- Branch set to https://github.com/puppetlabs/puppet/pull/1735
The cause was that Scope#to_hash did not include the local variables. That function was used by the TemplateWrapper to configure the available instance variables. Ergo – they were missing.
The fix includes the local variables, but skips all match (ephemeral) variables $0-$n just like the original implementation did. (i.e. it is backwards compatible).