----- Original Message -----
> From: "Martin Alfke" <[email protected]>
> To: "puppet-dev" <[email protected]>
> Sent: Tuesday, August 11, 2015 8:37:55 AM
> Subject: [Puppet-dev] Accessing variables from templates in wrapped defines

> Hi,
> 
> I have an issue with templates and variable lookup when used in wrapped 
> defines
> - which was working in older puppet versions (maybe due to the dynamic 
> variable
> lookup):
> 
> e.g. The following code:
> 
> The first define setting a local variable and calling a second define with a
> parameter:
> 
> cat define1/manifests/init.pp
> define define1 {
>  $var = 'test'
>  define2 { “define1_${name}":
>    template => 'define1/test.erb',
>  }
> }
> 
> The second define using a resource type and makes use of the parameter:
> 
> cat define2/manifests/init.pp
> define define2 ($template) {
>  notify { "define2_${name}":
>    message => template($template),
>  }
> }
> 
> The template which should be used in the second define (handed over as
> parameter):
> 
> cat define1/templates/test.erb
> test = <%= @var %>
> 
> The result:
> 
> puppet apply -e 'define1 { 'test': }'
> Notice: Compiled catalog for puppetmaster.example.net in environment 
> production
> in 0.33 seconds
> Notice: test =
> 
> Notice:
> /Stage[main]/Main/Define1[test]/Define2[define1_test]/Notify[define2_define1_test]/message:
> defined 'message' as 'test =
> '
> Notice: Applied catalog in 0.03 seconds
> 
> 
> If the first define would be a class then I could do a scope.lookupvar.
> If I change the template to do scope.lookupvar I receive the following:
> 
> puppet apply -e 'define1 { 'test': }'
> Warning: Scope(Define2[define1_test]): Could not look up qualified variable
> 'define1::var'; class define1 could not be found
> Notice: Compiled catalog for puppetmaster.example.net in environment 
> production
> in 0.32 seconds
> Notice: test =
> 
> Notice:
> /Stage[main]/Main/Define1[test]/Define2[define1_test]/Notify[define2_define1_test]/message:
> defined 'message' as 'test =
> '
> Notice: Applied catalog in 0.03 seconds
> 
> How can I access the variable from the first define?
> I can change the second define to have another parameter so it knows about the
> template variable.
> Is there any other solution available?

changing the 2nd define is the best solution, this already didn't work inside 
.pp files
for a long time and thankfully now it also doesnt work in templates

-- 
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/106951810.81856.1439278789473.JavaMail.zimbra%40devco.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to