During the task of writing a module, I found out that I have a huge amount of configurable parts. To better organize the module (for the sake of read- and maintainability), I have chosen to split template files up. As those template parts/fragments already sum up groups of configurable variables, I thought it might come handy to use hashes that represent the contents of the template fragments
(hash) $db -> template( config.db.erb ) (hash) $*** -> template( config.***.erb ) For some reason, I got something wrong with the Puppet/Ruby foo that I have set up, as only the thrown in hash values get used and the rest stays undef.
# Calling the module class { 'wppuppet': location => '/var/www/wp', db => { prefix => 'foo', user => 'usr', pass => '^[:D', }, } The actual init class inherits from the params defaults class
# init.pp class wppuppet( $location = $wppuppet::params::location, $db = $wppuppet::params::db ) inherits wppuppet::params { validate_hash( $db ) validate_string( $db['name'] ) # ... validate_bool( str2bool( $db['repair'] ) ) class { 'wppuppet::config': db => { prefix => $db['prefix'], name => $db['name'], user => $db['user'], pass => $db['pass'], host => $db['host'], repair => $db['repair'], } } # The params.pp defaults class class wppuppet::params { $db = { prefix => 'wp', name => 'wordpress', user => 'root', pass => 'root', host => 'localhost', charset => 'utf8', repair => true, } } Then there's the config.pp file containing the wppuppet::config class that generates the file from the concatenated templates.
# The actual config.php file file { "${location}/config.php": ensure => file, content => template( 'wppuppet/config.db.erb', 'wppuppet/config.debug.erb' # ... ), } And finally there's the config.database.erb file
define( 'DB_NAME', '<%= @db['name'] %>' ); define( 'DB_USER', '<%= @db['user'] %>' ); define( 'DB_PASSWORD', '<%= @db['pass'] %>' ); define( 'DB_HOST', '<%= @db['host'] %>' ); Edit Can someone explain me where I lost track and why I can't get the default values? When I place notice('params loaded') or simply dump the $db hash, I can see it being set in each class on the CLI, but not in the config.pp file / config class.