I'm attempting to use templating so that I can have variables in all config files for the aspects that vary solely based on which environment is in question. The benefit is that the only differences in the configurations between my environments are those being tested. This also eliminates the chance for human error; say leaving in host's domain names of the qa environment when roll out new configurations to staging.
How I initially wanted to perform this was to have a class for each environment to statically configure the variables in question in a single location. However, including this class at the node level didn't translate those values down to the template level. Here's an example of replacing puppet.conf for each environment with a template: Snippet from puppet.erb template -------------------------------------------------------------------------------- [puppetd] # Set by template server = <%= puppetserver %> environment = <%= environment %> -------------------------------------------------------------------------------- $environment is already a value known, however I'm creating the variable $puppetserver and trying to set it in one location. How I wanted to get this to work was to do something like this: -------------------------------------------------------------------------------- # templates.pp class qa_env { $puppetserver = "puppet.qa.domain" } class stage_env { $puppetserver = "puppet.stage.domain" } class prod_env { $puppetserver = "puppet.prod.domain" } -------------------------------------------------------------------------------- And thus each node would just "include" the appropriate class. This however does not work, so here is my work around. I created a single class to set each variable based on which environment the node in question happens to fall into. -------------------------------------------------------------------------------- # templates.pp class env_set { $puppetserver = $environment ? { qa => "puppet.qa.domain", stage => "puppet.stageg.domain", prod => "puppet.prod.domain", } } -------------------------------------------------------------------------------- The only problem is that in each node I not only include this class but also have to pull each variable up to the nodes scope for it's templates to be able to get values for these variables, as you see here: -------------------------------------------------------------------------------- # nodes.pp node "web-1" { include "env_set" $puppetserver = $env_set::puppetserver include "puppet::client" } node "web-2" { include "env_set" $puppetserver = $env_set::puppetserver include "puppet::client" } -------------------------------------------------------------------------------- This is fine for just a few variables, but it is going to get unmanagable as the number of nodes increases as well as the number of variables needed. Is there a better way to do this? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---