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