Re: [Puppet Users] Re: Variable Scoping: What do you want?

Jeff McCune
2010-07-05T20:57:36Z

On Mon, Jul 5, 2010 at 8:30 AM, TomTom <mcgonagle@gmail.com>
wrote:
> Hello All,
>  Thanks for opening up this discussion to the community. I quickly
> scanned through this thread, but didn''t see anything from Markus,
does
> he post under a different name.
>  Not to side track the conversation, but could anyone explain why
> variable scoping is the way it is in puppet? I "understand" how
to use
> variables in puppet (I ALWAYS use fully qualified variable names, and
> I ALWAYS use myvar.lookup in my templates.) But, I struggle to
> communicate to new puppet programmers why.
>
>  Is it because puppet is "declarative", is this a
"feature" in
> declarative languages? Is there a parallel in SQL?

Much of the variable referencing gotchas come from the declarative
nature of puppet.  It''s actually fairly straight forward
what''s
happening (in my opinion).  You cannot re-declare a variable in the
same scope because of the declarative nature of puppet, puppet does
not know which declaration is "right" since order doesn''t
matter.

You can, however declare the same variable name in a different scope
however.  They''re actually different variables.

In module "jeff" I create class jeff::params {} in manifests/params.pp
and place variables here.  This allows me to reference
$params::shirtcolor from class jeff.  Note too I''m not using absolute
name-space syntax.

Finally, in 0.25.x the parser is single-pass which causes some of the
constraints and inconsistencies with variable declarations related to
their order inside manifests.  In the future, the parser will be
multi-pass which will correct these inconsistencies.

Hope this helps,
--
Jeff McCune