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?
Thanks,
Martin