Issue #4717 has been updated by Paul Berry.

Target version set to Statler
Affected version changed from 2.6.1rc2 to 0.25.5

I spent some time debugging this and it is not what it seemed at first.

The problem is a combination of these factors:

* variable definitions, function calls, and resources that appear at toplevel 
are treated as though they appear in an invisible class called :main.

* the contents of identically-named classes that appear in separate files are 
merged together in the order that those files _finished_ processing.

* variable evaluation is order-dependent--a variable's value can't be seen 
until it is set.

Considering Dan's example from comments 3 and 4: Puppet interprets it as 
declaring three entities: a node and two :main classes:

class :main from /tmp/puppettest/site.pp:
<pre>
$testvar = 'TESTVAR_VALUE'
notice("testvar in site.pp is: ${testvar}")
</pre>

class :main from /tmp/puppettest/nodes.pp:
<pre>
notice("testvar outside node is: ${testvar}")
</pre>

node test.puppet.cms.ucar.edu from /tmp/puppettest/nodes.pp:
<pre>
notice("testvar inside node is: ${testvar}")
</pre>

Since Puppet pauses the parsing of site.pp to import nodes.pp, it finishes 
parsing nodes.pp first, so when the :main classes are merged together, 
nodes.pp's :main goes first:

Merged :main class:
<pre>
notice("testvar inside node is: ${testvar}")
$testvar = 'TESTVAR_VALUE'
notice("testvar in site.pp is: ${testvar}")
</pre>

So the problem is not that global variables aren't global.  It's that variables 
are only accessible after they're declared, and the order relationships between 
different files is counterintuitive.

Note: AFAIK all these problems also exist in 0.25.x.
----------------------------------------
Bug #4717: Global variables are no longer fully global
http://projects.puppetlabs.com/issues/4717

Author: Dan Urist
Status: Needs more information
Priority: Normal
Assignee: 
Category: 
Target version: Statler
Affected version: 0.25.5
Keywords: global variable scope
Branch: 


A variable defined in global scope is no longer visible in the global scope of 
other files. For example:

site.pp:

   $testvar = "TESTVAR_VALUE"

nodes.pp:

   notice("testvar outside node is: ${testvar}")
   node 'test.puppet.cms.ucar.edu' {
     notice("testvar inside node is: ${testvar}")
   }

The log contains this after a puppet run:

puppet-master[3758]: (Scope(Class[main])) testvar outside node is: 
puppet-master[3758]: (Scope(Node[test.puppet.cms.ucar.edu])) testvar inside 
node is: TESTVAR_VALUE

If I move the node definition to site.pp, so it is in the same file as the 
variable definition, then it's defined both outside and inside the node 
definition.

I haven't tested whether the same issue exists for classes as well as nodes. 
Note that the behavior in 0.25 was that the global variable was defined 
everywhere, which is what I would expect (and is the behavior some of my 
modules rely on).


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to