-
-
Save tuxfight3r/f1e20d5a50282bb08ebfd72a866a55f1 to your computer and use it in GitHub Desktop.
sorted hash in puppet templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| databases => { | |
| 'default' => | |
| { | |
| 'ENGINE' => 'postgresql_psycopg2', | |
| 'NAME' => 'defaultdb', | |
| 'HOST' => '2.2.2.2.2', | |
| 'USER' => 'username', | |
| 'PASSWORD' => 'secretinfo', | |
| 'OPTIONS' => | |
| { | |
| 'sslmode' => 'require', | |
| 'otheroption' => 'yep' | |
| } | |
| }, | |
| 'db2' => | |
| { | |
| 'ENGINE' => 'postgresql_psycopg2', | |
| 'NAME' => 'db2', | |
| 'HOST' => '1.1.1.1', | |
| 'USER' => 'db2user', | |
| 'PASSWORD' => 'extrasecretinfo', | |
| 'OPTIONS' => | |
| { | |
| 'foo' => 'bar', | |
| 'bar' => 'foo', | |
| } | |
| } | |
| }, | |
| template | |
| ------------- | |
| DATABASES = { | |
| <% databases.keys.sort.each do |key| -%> | |
| '<%= key %>': { | |
| <% databases[key].keys.sort.each do |param| -%> | |
| <% if param !='OPTIONS' -%> | |
| '<%= param %>': '<%= databases[key][param] %>', | |
| <% end -%> | |
| <% end -%> | |
| <% if databases[key].has_key?("OPTIONS") -%> | |
| 'OPTIONS': { | |
| <% databases[key]["OPTIONS"].keys.sort.each do |opts| -%> | |
| '<%= opts %>': '<%= databases[key]["OPTIONS"][opts] %>', | |
| <% end -%> | |
| } | |
| <% end -%> | |
| } | |
| <% end -%> | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment