1
0
mirror of https://github.com/krislamo/puppet-rsnapshot synced 2024-11-10 00:00:35 +00:00

add custom function to allow for empty hashes in params (specify hostname only to pickup defaults)

This commit is contained in:
Norbert Varzariu 2015-12-19 21:13:55 +01:00
parent f7922a2e4a
commit fa88ccb1cb
2 changed files with 16 additions and 4 deletions

View File

@ -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?

View File

@ -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)