On 09/23/2010 09:06 PM, James Cammarata wrote:

Here's the way we do it, and it works very well for us, while avoiding
"globals" and the associated issues.

First, we have a "basezone" class, which is empty and really is just a
place holder (you'll see what this is for in a minute):

Thanks for the reply !

Simplifying your example, then :

class foo {
  $foo_var = "beer"
}

class bar {
  include foo
  # we could assign it here...
  $bar_var = $::foo::foo_var
  file { 'template':
    content => template('bar/template.erb')
  }
}


With "template.erb":

This is foo_var as determined by bar : <%= bar_var =>
Or directly from foo : <%= scope.lookupvar('foo::foo_var') %>


Applying this distilled example to my previously stated scenario, then, we might have something like :

# include this where appropriate
class getsite {
  $site_name = $domain ? {
    'abc.dom.ain' => 'abc',
    'xyz.dom.ain' => 'xyz',
  }
  $site_ip = $domain ? {
    'abc.dom.ain' => '1',
    'xyz.dom.ain' => '2',
  }
}

# yes i know there's a module for this; this is just a contrived example
class resolv {
  include getsite
  file { '/etc/resolv.conf:
    content => template('resolv/resolv.conf.erb')
  }
}


With template "resolv.conf.erb" :
search <%= scope.lookupvar('getsite::site_name') %>.dom.ain
server 10.<%= scope.lookupvar('getsite::site_ip') %>.0.1


This works exactly as it appears, and is a reasonable approach, though in my example scenario the scope is limited ; i would harbour concerns about tracking this though many levels of scope (as you have) without proper internal documentation. :)

Thanks for the idea !

--
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