On 09/24/2010 02:57 PM, James Cammarata wrote:

That's the good thing about the way we do it - there's only one level of
scope: basezone.  Every variable we define in all the classes along the way
is visible at that level, so we don't have to remember class names of all
the stuff in the middle.  Your version makes things more complex, because
you have to remember that your domain variable is in getsite.  Also, I
don't think you'd be able to include getsite more than once - I think you'd
get a variable redefinition error.  And we do try and use puppetdoc to
explain class internals as much as possible, so the new guys know what
classes they need to include.

Some interesting points, to be sure. As for including getsite more than once, consider :

class getsite {
  # method to obtain $site_name goes here
}

class foo {
  include getsite
  file { 'template':
    content => template('foo/template.erb')
  }
}

class bar {
  include getsite
  file { 'template':
    content => template('bar/template.erb')
  }
}

node 'srv1' {
  include foo
  include bar
}

node 'srv2' {
  include foo
  include bar
}

# <bar|foo>/template.erb
Site is : <%= scope.lookupvar('getsite::site_name') %>
# EOF


That works - i just tried it.  No problems.  In fact, this works, too :

class bar {
  include getsite
  include foo         # which already has getsite in it
}


If the value of "$site_name" were to change depending on which class was calling it, then i could see that being a problem - but that doesn't happen in this case.


In any case, looking back at your original reply, i am getting a little lost on the logic. I drew your include relationships out on the whiteboard here and it doesn't quite make sense to me ; i'll try to re-create it here (i hope your client uses a fixed-width font :) ).

.---------------------------------------------------.
| class dc1_zone1                                   |
| .--------------------. .------------------------. |
| | class dc1          | | class basenode         | |
| | .----------------. | | .--------------------. | |
| | | class basezone | | | | class role_general | | |
| | '----------------' | | '--------------------' | |
| '--------------------' '------------------------' |
'---------------------------------------------------'

Breaking the scopes down :
dc1_zone1 : All variables in all classes
dc1 : Variables in dc1 and basezone only
basezone : Variables in basezone only
basenode : All variables in basenode and role_general
role_general : All variables in role_general

Your stated example includes logic from role_general, which in turn looks for a variable in basezone. This leads to two questions : 1. If basezone is empty (a place holder, as you mentioned), where is the variable coming from ? 2. How can role_general go look for a variable that is outside of its scope ?

For question #2, i am hypothesising that the variable is out of scope, but that the ruby call to scope.lookupvar somehow deals with that problem, and "finds" the variable anyway ?

Alternatively, i have completely and utterly misunderstood the fundamentals of scoping in Puppet (eminently possible). Is it that given the class relationship described above, role_general has access to basezone's scope because they are both "included" together at a higher level ?

Thank you for your continued commentary on this topic.


--
Daniel Maher <dma AT witbe DOT net>
"The Internet is completely over." -- Prince

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To post to this group, send email to puppet-us...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to