[Puppet Users] Re: how to define variables in module scope ?

2008-10-03 Thread Luke Kanies

On Oct 3, 2008, at 1:04 PM, David Lutterkort wrote:


 On Thu, 2008-10-02 at 11:31 -0500, Luke Kanies wrote:
 In the meantime, though, scoped variables should get you pretty  
 close:

 #manifests/init.pp
 class mymod {
   $foo = important stuff
 }

 #manifests/other.pp
 class mymod::other {
   $other = even more ${foo}
 }

 Isn't that missing an inherits or include of mymod in mymod::other ?



Derr, I mean even more ${mymod::foo}.

-- 
The truth is that there is nothing noble in being superior to somebody
else. The only real nobility is in being superior to your former self.
 -- Whitney Young
-
Luke Kanies | http://reductivelabs.com | http://madstop.com


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



[Puppet Users] Re: how to define variables in module scope ?

2008-10-03 Thread David Lutterkort

On Thu, 2008-10-02 at 11:31 -0500, Luke Kanies wrote:
 In the meantime, though, scoped variables should get you pretty close:
 
 #manifests/init.pp
 class mymod {
$foo = important stuff
 }
 
 #manifests/other.pp
 class mymod::other {
$other = even more ${foo}
 }

Isn't that missing an inherits or include of mymod in mymod::other ?

David



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



[Puppet Users] Re: how to define variables in module scope ?

2008-10-02 Thread Marc Fournier

Hello,

  I have a bunch of variables that are used in several classes and
  definitions, all part of the same module.
 
  As these variables are defined automatically based on system facts,
  I would like to avoid having to declare them in each node that uses
  classes or definitions from my module.
 
  Where would be the best place to put these variables ? I tried in
  module/manifests/init.pp as well as in an external file imported  
  from
  within classes/definitions files but none work as I would have  
  expected.
 
 That's a discussion I had several weeks ago on IRC, but I can't  
 remember with whom. IIRC, it basically makes a difference wheter the  
 module is autoloaded or imported. My tests so far have shown that  
 module-scope variables, i.e. e.g. such ones defined at the
 beginning of init.pp, get included if you import the module, but not
 if some class in the module is autoloaded. I think we had concluded
 that it would be nice to have module-scope variables in autoloaded
 classes and definitions, but had not followed the thought or the
 tests any further.
 
 I hope this answers some of your questions, and we can find a
 solution that suits everyone. Greetings,

Thank you Felix for this idea ! It indeed helped my classes work
without having to set variables in the global scope.

For future reference, here's the idea:

modules/whatever/manifests/init.pp:

case $operatingsystem {
  RedHat: {
$wwwuser = apache
  }
  Debian: {
$wwwuser = www-data
  }
}

import classes/*.pp
import definitions/*.pp

In modules/whatever/manifests/*/*.pp I have stuff such as:

class wwwuser {
  user { $wwwuser:
ensure  = present,
  }
}

And finally in my nodes I do:

  import whatever
  include wwwuser

This solution is convenient enough for my needs. But maybe should we
report this as a feature request to puppet developers ?
Does someone know if there is a good reason variables in init.pp
aren't available in autoloaded classes ?

If this is finally the designed behaviour I will put a note somewhere in
the wiki about the workaround.

Marc




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



[Puppet Users] Re: how to define variables in module scope ?

2008-10-02 Thread Luke Kanies

On Sep 29, 2008, at 12:45 PM, Felix Schäfer wrote:


 Hello,

 Am 29.09.2008 um 18:40 schrieb Marc Fournier:

 I have a bunch of variables that are used in several classes and
 definitions, all part of the same module.

 As these variables are defined automatically based on system facts, I
 would like to avoid having to declare them in each node that uses
 classes or definitions from my module.

 Where would be the best place to put these variables ? I tried in
 module/manifests/init.pp as well as in an external file imported
 from
 within classes/definitions files but none work as I would have
 expected.

 That's a discussion I had several weeks ago on IRC, but I can't
 remember with whom. IIRC, it basically makes a difference wheter the
 module is autoloaded or imported. My tests so far have shown that
 module-scope variables, i.e. e.g. such ones defined at the beginning
 of init.pp, get included if you import the module, but not if some
 class in the module is autoloaded. I think we had concluded that it
 would be nice to have module-scope variables in autoloaded classes
 and definitions, but had not followed the thought or the tests any
 further.

Puppet doesn't actually currently have any concept of module-scoped  
variables.  Really, the language doesn't even know anything about  
modules -- they're convenient ways of organizing files, but they don't  
affect things like variable scope.

What you're seeing is a difference in behaviour in defining *global*  
variables -- anything outside of all classes is actually available in  
every class in the system, not just the classes in that module.

I'd consider adding module variables if we could come up with a good  
way to do it, but I can't think of a mechanism.

In the meantime, though, scoped variables should get you pretty close:

#manifests/init.pp
class mymod {
   $foo = important stuff
}

#manifests/other.pp
class mymod::other {
   $other = even more ${foo}
}

-- 
I take my children everywhere, but they always find their way
back home. --Robert Orben
-
Luke Kanies | http://reductivelabs.com | http://madstop.com


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



[Puppet Users] Re: how to define variables in module scope ?

2008-09-29 Thread Felix Schäfer

Hello,

Am 29.09.2008 um 18:40 schrieb Marc Fournier:

 I have a bunch of variables that are used in several classes and
 definitions, all part of the same module.

 As these variables are defined automatically based on system facts, I
 would like to avoid having to declare them in each node that uses
 classes or definitions from my module.

 Where would be the best place to put these variables ? I tried in
 module/manifests/init.pp as well as in an external file imported  
 from
 within classes/definitions files but none work as I would have  
 expected.

That's a discussion I had several weeks ago on IRC, but I can't  
remember with whom. IIRC, it basically makes a difference wheter the  
module is autoloaded or imported. My tests so far have shown that  
module-scope variables, i.e. e.g. such ones defined at the beginning  
of init.pp, get included if you import the module, but not if some  
class in the module is autoloaded. I think we had concluded that it  
would be nice to have module-scope variables in autoloaded classes  
and definitions, but had not followed the thought or the tests any  
further.

I hope this answers some of your questions, and we can find a solution  
that suits everyone. Greetings,

Felix Schäfer
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To post to this group, send email to puppet-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~--~~~~--~~--~--~---