Oren Marmor
2012-Aug-07 17:07 UTC
[Puppet Users] setting different values to same variables
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! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/EHH6EX7k8UUJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Axel Bock
2012-Aug-08 05:49 UTC
[Puppet Users] Re: setting different values to same variables
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 import more_defs.qa and import more_defs.dev 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. Am Dienstag, 7. August 2012 19:07:49 UTC+2 schrieb Oren Marmor:> > 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! >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/V5h5fIiqOZYJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Aug-08 13:37 UTC
[Puppet Users] Re: setting different values to same variables
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 > import more_defs.qa > and > import more_defs.dev > 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 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/0ICIVY5xCbkJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Oren Marmor
2012-Aug-08 15:43 UTC
[Puppet Users] Re: setting different values to same variables
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. On Wednesday, August 8, 2012 4:37:23 PM UTC+3, jcbollinger wrote:> > > > 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 >> import more_defs.qa >> and >> import more_defs.dev >> 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 > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/7tDbmSV8u_sJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Aug-08 21:54 UTC
[Puppet Users] Re: setting different values to same variables
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 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/XmFSnTLxe0gJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.