From fa88ccb1cbe76fc1047f03bcf8a0dfa540149652 Mon Sep 17 00:00:00 2001 From: Norbert Varzariu Date: Sat, 19 Dec 2015 21:13:55 +0100 Subject: [PATCH] add custom function to allow for empty hashes in params (specify hostname only to pickup defaults) --- lib/puppet/parser/functions/pick_undef.rb | 4 ++-- manifests/config.pp | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/puppet/parser/functions/pick_undef.rb b/lib/puppet/parser/functions/pick_undef.rb index 3e55a4a..f62cd78 100644 --- a/lib/puppet/parser/functions/pick_undef.rb +++ b/lib/puppet/parser/functions/pick_undef.rb @@ -1,6 +1,6 @@ module Puppet::Parser::Functions - newfunction(:pick_undef, :type => :rvalue, :doc => <<-EOS - This function is similar to pick_default, but will return or undefined values. +newfunction(:pick_undef, :type => :rvalue, :doc => <<-EOS +This function is similar to pick_default, but will return or undefined values. EOS ) do |args| fail "Must receive at least one argument." if args.empty? diff --git a/manifests/config.pp b/manifests/config.pp index 975bf8e..9fac8fd 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -16,8 +16,21 @@ class rsnapshot::config ( ensure => 'directory', } + # $hosts_clean = $hosts.reduce( {} ) |$memo, $entry| { + # $key = $entry[0] + # $value = $entry[1] + # $new_value = $value ? { + # undef => {}, + # default => $value, + # } + # $memo + { $key => $new_value } + # } + # + $hosts_clean = assert_empty_hash($hosts) notify {"Hosts is: $hosts ": } - $hosts.each |String $host, Hash $hash | { + notify {"Hosts_clean is: $hosts_clean ": } + + $hosts_clean.each |String $host, Hash $hash | { $snapshot_root = pick($hash['snapshot_root'], $rsnapshot::params::config_snapshot_root) $backup = pick($hash['backup'], $rsnapshot::params::config_backup) $backup_user = pick($hash['backup_user'], $rsnapshot::params::config_backup_user) @@ -27,7 +40,6 @@ class rsnapshot::config ( } else { $backups = $backup } - $cmd_cp = pick($hash['cmd_cp'], $rsnapshot::params::config_cmd_cp) $cmd_rm = pick($hash['cmd_rm'], $rsnapshot::params::config_cmd_rm) $cmd_rsync = pick($hash['cmd_rsync'], $rsnapshot::params::config_cmd_rsync)