according to http://docs.puppetlabs.com/guides/scope_and_puppet.html
about dynamic lookup from an included puppet file:
puppet 2.7 warns about it, and puppet 3.2 stops working, as expected.
however,
about dynamic lookup from a template called on an included puppet file:
both puppet 2.7 and puppet 3.2 it works, without even a warning. (see in
red the below example)
Why is that?
And so, does this mean that dynamic lookup is bad from a puppet file, but
not from a template file?
See below a specific example:
test.pp
class c1 {
$var = 'hello'
notify {"var from c1: $var": }
include c2
}
class c2 {
notify {"var from c2: $var": }
file { '/tmp/file.txt':
content => template('file.txt.erb'),
}
}
class { c1: }
file.txt.erb
var from file.txt.erb: <%= @var %>
----
running with puppet 2.7.19:
$ puppet apply --templatedir templates/ test.pp
*warning: Dynamic lookup of $var at /vagrant/t1/test.pp:8 is deprecated.*For
more information, see
http://docs.puppetlabs.com/guides/scope_and_puppet.html. To see the change
in behavior, use the --debug flag.
notice: var from c1: hello
notice: /Stage[main]/C1/Notify[var from c1: hello]/message: defined
'message' as 'var from c1: hello'
notice: /Stage[main]/C2/File[/tmp/file.txt]/ensure: defined content as
'{md5}ea0d73f3957b0893f63e03cb9d8c9d98'
*notice: var from c2: hello*
notice: /Stage[main]/C2/Notify[var from c2: hello]/message: defined
'message' as 'var from c2: hello'
notice: Finished catalog run in 0.05 seconds
$ cat /tmp/file.txt
*var from file.txt.erb: hello*
running with puppet 3.3.2:
$ puppet apply --templatedir templates/ test.pp
Notice: Compiled catalog for mac4c.local in environment production in 0.16
seconds
Notice: var from c1: hello
Notice: /Stage[main]/C1/Notify[var from c1: hello]/message: defined
'message' as 'var from c1: hello'
*Notice: var from c2: *
Notice: /Stage[main]/C2/Notify[var from c2: ]/message: defined 'message' as
'var from c2: '
Notice: /Stage[main]/C2/File[/tmp/file.txt]/ensure: defined content as
'{md5}ea0d73f3957b0893f63e03cb9d8c9d98'
$ cat /tmp/file.txt
*var from file.txt.erb: hello*
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" 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-users/70380351-7612-4b51-b338-8bb7eadeac83%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.