and according to http://docs.puppetlabs.com/guides/templating.html
*All of the variables visible in the current scope are available as Ruby 
instance variables*
but out of the scope variables should be accessed by scope.lookupvar.

so, why does the previous example works? why does file.txt get the 'hello' 
value?
*var from file.txt.erb: hello*



On Wednesday, November 27, 2013 2:40:41 PM UTC+1, David Portabella wrote:
>
> 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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/da8a8221-a5a7-4a1e-bec4-f9ae93b9f389%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to