On Mon Dec 15 2014 at 6:07:43 PM John Sellens <[email protected]> wrote:

> I couldn't find any reference to this different behaviour, so I'm
> wondering if anyone knows if this is intentional.
>
> I use a bunch of defined types, and with the future parser, when I refer
> to a variable in a template, it seems that the default scope is not the
> scope of the class.
>
> e.g. in a template, <%= @a %> no longer refers to $a from the current
> class.
>
> This is different behaviour than with the current parser, and doesn't
> seem to match the documentation I've found, or the behaviour with the
> standard types.
>
>
> For example, I have a module called "parsetest" and the init.pp is:
>
>     define fileerb ( ) {
>         file { "/tmp/$name":
>             content => template( "parsetest/${name}.erb" ),
>         }
>     }
>
>     class parsetest {
>
>         $a = "hello"
>
>         fileerb { "bloop" : }
>
>     }
>
> The templates/bloop.erb contains:
>
>     the value of a is: <%= @a %>
>
> In current puppet, the value of $a ends up in /tmp/bloop.
> With the future parser, no value is used, and I don't see
> any errors.
>
> I see this in puppet 3.7.3 (from the puppetlabs yum repo) and
> also in 3.6.2 (from freebsd ports).
>
>
> Is it expected that a defined type evaluates templates in a
> (seemingly) different scope?
>

Yes, this is expected. Defined types have their own scope which doesn't
inherit variables from the class they are instantiated from.

So if you need the variable in the define, forward it to it using a
parameter.


In Puppet 3.x that behaviour worked in templates, but not outside
templates. With future parser it is more consistent.

-- 
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/CAAAzDLem3VYuJxT05VqerKtW1MVKiAn1VBs%3DKR6R5bdeF_YR7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to