Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
ugh, custom function
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Huff committed Sep 30, 2015
1 parent 29e3504 commit d4d7dd3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 18 additions & 0 deletions lib/puppet/parser/functions/merge_hashes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'deep_merge'

module Puppet::Parser::Functions
newfunction(:merge_hashes, :type => :rvalue, :doc => "Performs a deep merge on multiple hashes passed in as arguments.") do |args|
begin
merged = {}

args.each do |arg|
merged.deep_merge!(arg, { :merge_hash_arrays => true })
end

merged

rescue StandardError => e
raise Puppet::ParseError, e.message
end
end
end
8 changes: 5 additions & 3 deletions manifests/tomcat.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
}

# Postgres
$postgres = lookup('rk_tomcat::tomcat::postgres', { 'merge' => { 'strategy' => 'deep', 'merge_hash_arrays' => true }, 'value_type' => Hash })
$postgres_resources = $postgres.map |$key,$values| {
$postgres = lookup('rk_tomcat::tomcat::postgres', { 'value_type' => Hash })
$postgres_secrets = lookup('rk_tomcat::tomcat::postgres_secrets', { 'value_type' => Hash })
$postgres_merged = merge_hashes($postgres, $postgres_secrets)
$postgres_resources = $postgres_merged.map |$key,$values| {
{
'name' => $values[name],
'url' => "jdbc:postgresql://${values[host]}:${values[port]}/${values[db]}",
Expand All @@ -47,7 +49,7 @@
}
}

notify { "postgres: $postgres": }
notify { "postgres: $postgres_merged": }

# Logentries
$logentries_analytics_token = $logentries_tokens['analytics']
Expand Down

0 comments on commit d4d7dd3

Please sign in to comment.