On Tuesday, May 27, 2014 6:53:29 AM UTC-5, Felix.Frank wrote:
>
> On 05/26/2014 06:40 PM, Fabrice Bacchella wrote: 
> > Is that normal that params1 is part of the context in both case, but not 
> param2 ? 
>
> Ugh. Scope semantics. It *does* seem a little weird. Here's my take: 
>


I don't think it's even weird, once you understand that Puppet does not 
have nested scopes.  It has global scope and local scopes, and on the DSL 
side it has a mechanism for consulting a hierarchy of multiple scopes 
(based on name components, not on lexical nesting or declaration chains) to 
resolve relative names.

The Puppet variables available in a template directly from the scope object 
are the locals of the scope from which template() or inline_template() was 
called, plus (I think) the globals that are not shadowed by locals.


Your template is evaluated from inside these defined type instances: 
> Mytpe[mytype] 
> Mysubtype[/tmp/parsed1] 
>
>

That is exactly the key.

 

> Therefor $name and $title *must* take the values 'mytype' and 
> '/tmp/parsed1' respectively. Anything else would be quite inconsistent. 
>
>

Quite so.  And it's not just a question of consistency -- it's the right 
answer.  When the template is evaluated (directly) by Mytype['mytype'], the 
locals $name and $title both have the value 'mytype', and there is another 
local, $param2.  When the template is evaluated by 
Mysubtype['/tmp/parsed1'], the locals $name and $title both have value 
'/tmp/parsed1', and there are additional locals $filepath and $source, but 
there is no local $param2.

Also, $param1 should not be part of *either* scope, contrary to the OP's 
remark that it is part of both.  The diff does not support the OP's claim, 
which I suspect is an incorrect inference.  If $param1 really is in both 
scopes, though, then that is inconsistent with Puppet's scoping 
documentation<http://docs.puppetlabs.com/puppet/latest/reference/lang_scope.html>
.

Finally, I observe that the templates are a bit of a red herring here.  
They provide a convenient way to enumerate the contents of a scope, but the 
differences in the contents of scopes presented to them are not a question 
of templating.


John

-- 
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/c3fdab4c-e2c3-4c34-b2af-876d1b1f0c35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to