Skip to content

Instantly share code, notes, and snippets.

@vStone
Created December 18, 2012 06:45
Show Gist options
  • Save vStone/4325626 to your computer and use it in GitHub Desktop.
Save vStone/4325626 to your computer and use it in GitHub Desktop.
Puppet hashes weird behaviour
## Config created by foreman-database.yml.erb
production:
adapter: mysql2
name: puppet_test
password: password
server: localhost
user: puppet
## This is wrong. Should have been
#production:
# adapter: mysql2
# name: puppet_test
# password: password
# server: localhost
# user: puppet
## Called from the foreman clasS
<%= scope.lookupvar('foreman::environment') %>:
<%
dbsettings = scope.lookupvar('foreman::database_settings') || {}
dbsettings.keys.sort.each do |key|
value = dbsettings[key]
-%>
<%= key %>: <%= value %>
<% end %>
#### Node ####
node 'puppetmaster' {
$database_settings = {
'adapter' => 'mysql2',
'database' => 'puppet_test',
'host' => 'localhost',
'username' => 'puppet',
'password' => 'password',
}
class {'puppet::server':
storeconfig_settings => $database_settings,
}
class {'foreman':
database_settings => $database_settings,
}
}
### Config created by puppet::server (puppet.conf.erb)
[master]
storeconfigs = true
dbadapter = mysql2
dbname = puppet_test
dbpassword = password
dbserver = localhost
dbuser = puppet
## Called fro
m the puppet::server class
[master]
storeconfigs = <%= scope.lookupvar("puppet::server::storeconfigs") %>
<%
if scope.lookupvar('puppet::server::storeconfigs')
settings = scope.lookupvar('puppet::server::storeconfig_settings') || {}
map = {
'username' => 'user',
'database' => 'name',
'host' => 'server',
}
settings.keys.each { |k| settings[map[k]] = settings.delete(k) if map[k] }
settings.keys.sort.each do |key|
value = settings[key]
-%>
db<%= key %> = <%= value %>
<% end -%>
<% end -%>
production:
adapter: mysql2
name: puppet_test
password: password
server: localhost
user: puppet
### This is obviously wrong. I need the original keyvalues here but they got altered in the puppet.conf template.
@ahpook
Copy link

ahpook commented Dec 20, 2012

@vStone i don't doubt that the behaviour you're seeing is real, but the example code doesn't show it AFAIK -- the commented section where you say "this is wrong" is the same as the uncommented section above, and that ends up the same as the output section of your puppet.conf.erb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment