setting different values to same variables

37 views
Skip to first unread message

Oren Marmor

unread,
Aug 7, 2012, 1:07:49 PM8/7/12
to puppet...@googlegroups.com
Hi all.
i have a design question and would appreciate your suggestions.
i would like to use templates to define files on nodes according to the node's environment, for example dev,qa
problem is i have many variables in many groups and defining them all in one file would be pretty ugly
i would like to split each group definitions to a separate file and load it only if i am running in that environment - like source command in shell
using parameterized classes would still require me to send all different values and would not be very readable 

end result should be:
1. a variable named port (for example) with the value of 80 in one environment and 8080 in the other
2. values for variables of each environment in a different file for easy management.

my template looks something like this:
env.erb:
export port=<%=port%>
--snip--

and a class with the variables i want to define but instead of literally writing all variables do something like import 
case $env {
  /dev(.*)/: {
     $port=80
     import more_defs.dev
  }
/qa(.*)/: {
     $port=8080
     import more_defs.qa
  }
}

suggestions?
thanks!

Axel Bock

unread,
Aug 8, 2012, 1:49:57 AM8/8/12
to puppet...@googlegroups.com
Hi Oren,

I'm kind of new to puppet myself - but I think this is not working as you might like. If you import a class with your definitions, your scope changes AFAIK. So between
and
there is - again: AFAIK - one major disadvantage. Using classes you will get different scopes for your variables - in the first case you'll get more_defs.qa::myvar, and in the 2nd case more_defs.dev::myvar as variable. probably no good.

I would maybe put all the defs and no functionality in one (yes, ugly) class and just refer to them from all other modules. 


HTH.
Axel.

jcbollinger

unread,
Aug 8, 2012, 9:37:23 AM8/8/12
to puppet...@googlegroups.com


On Wednesday, August 8, 2012 12:49:57 AM UTC-5, Axel Bock wrote:
Hi Oren,

I'm kind of new to puppet myself - but I think this is not working as you might like. If you import a class with your definitions, your scope changes AFAIK. So between
and
there is - again: AFAIK - one major disadvantage. Using classes you will get different scopes for your variables - in the first case you'll get more_defs.qa::myvar, and in the 2nd case more_defs.dev::myvar as variable. probably no good.


I think you're confusing 'import' with 'include'.  It should be possible to put variable declarations at top-scope (outside any class or definition) in a manifest, and to 'import' that manifest at top scope to make them visible as global variables.  But that's ugly and brittle.  The 'import' function has very few good uses, and this is not one of them.

This sort of problem is hiera's bread and butter.  Although it is an extension to Puppet 2, hiera will be built into Puppet 3, so using it now is also forward-looking.


John

Oren Marmor

unread,
Aug 8, 2012, 11:43:13 AM8/8/12
to puppet...@googlegroups.com
John, Axel, thanks for your comments
defining default variable in module top-scope is exactly what i did but like you said, its not very pretty.
i'll look at hiera, any ideas when its supposed to be released in puppet3?

Oren.

jcbollinger

unread,
Aug 8, 2012, 5:54:04 PM8/8/12
to puppet...@googlegroups.com


On Wednesday, August 8, 2012 10:43:13 AM UTC-5, Oren Marmor wrote:
John, Axel, thanks for your comments
defining default variable in module top-scope is exactly what i did but like you said, its not very pretty.
i'll look at hiera, any ideas when its supposed to be released in puppet3?


Puppet 3 (which is not yet released) will include hiera from the very beginning.  It is pretty deeply integrated with class parametrization.  In the mean time, lots of people use hiera with Puppet 2.


John

Reply all
Reply to author
Forward
0 new messages