zuber@puzzle.ch
2010-May-07 10:03 UTC
[Puppet Users] variables in variable and class names
Hi, this may sound a bit strange, so let me tell you first what the problem is that i try to solve and maybe there is already a better solution. Some background: We use 3 different environments on our puppetmaster and we implemented something like a release management as a workflow for this. Cause why should you invent something new when you can steal it from software engineers ;-). The release management is a simple tag convention in the version management and a post-receive script that makes a checkout the newest version for each environment. We have a release cycle where we tag a version for integration that worked without regression for a while on the testing environment. For production exactly the same. Now there are sometimes settings, config files or classes that only apply on a single host and the whole release cycle makes no sense and you really don''t want to wait some days until the new firewall rule apply on a production system because there are already other changes in the pipe and you can''t just "tag it trought". So my plan is to have a special module that is always checked out from HEAD in every environment and the classes there, if defined are only applied on a singe host, never group of hosts. If they are not defined the host is just uses the defaults. For files this is easy, but for variables or classes i found no way so far to implement this. Here is an NON working example that may describe what i want to do: ----------------------------------------------------------- # Settings i want to overwrite only for "mynewserver". # This class is only there if i need at least one special settings class hostconfig::mynewserver::settings { $myvar = "overwritten for this host" } # Load the settings class if it exists if defined( hostconfig::${hostname}::settings ) { include hostconfig::${hostname}::settings } # if we need a variable that can be overwritten i have to check # if it exists. If it does not we use the default value. if defined( $hostconfig::${hostname}::settings::myvar ) { $var = $hostconfig::${hostname}::settings::myvar } else { $var = "default" } notice( $var ) ------------------------------------------------------------------ If the host is a standard system i should i want to do absolutely nothing, cause it gets its classes and settings from regex patterns in the default node config based on the server name (We only have a hand full of different servers but many of them). Any ideas how i can implement this in a way that works? -- 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 puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Does class hostconfig::mynewserver::settings contain just variables? You could do something like this (from http://groups.google.com/group/puppet-users/browse_thread/thread/5ba9d8b1ed4d4d1a/1214d616ef5caec0)... ==In my nodes.pp, I define certain "default" variables at the top of the manifest, outside of any node definitions. If I want to override a default variable, I redefine the variable inside of the specific node definition, before I include the class that uses the variable. For example:> cat nodes.pp# defaults $dnsname = "foo.local" $dnsserver = [ "192.168.1.1", "192.168.2.1" ] $dnssearchpath = [ "foo", "foo.local" ] node "standard.node" { include basenode } node "nonstandard.node" { $dnsname = "bar.local" $dnsserver = [ "192.168.100.1", "192.168.101.1" ] $dnssearchpath = [ "bar", "bar.local" ] include basenode } -- 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 puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.