diff --git a/TODO b/TODO index 09dbfdd..8e6d55c 100644 --- a/TODO +++ b/TODO @@ -1 +1,3 @@ validate for puppet 3 => impossible, misses the .each function + +Fix Documentation diff --git a/lib/puppet/parser/functions/assert_empty_hash.rb b/lib/puppet/parser/functions/assert_empty_hash.rb index fb90c2c..6af212f 100644 --- a/lib/puppet/parser/functions/assert_empty_hash.rb +++ b/lib/puppet/parser/functions/assert_empty_hash.rb @@ -4,6 +4,8 @@ This function checks an input struct for undefined hashes in key => hash and ass EOS )do |args| fail "Must receive one argument." if args.empty? + return args if args.is_a?(String) + return args if args.is_a?(Integer) args.each do |arg| h = Hash.new arg.each_pair do |host, hash| diff --git a/manifests/config.pp b/manifests/config.pp index 0134dd4..1317bb2 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -117,23 +117,51 @@ class rsnapshot::config ( concat { $cronfile: } $backup_levels.each |String $level| { - if validate_hash($hash) { + # allow to globally override ranges, create random numbers for backup_levels daily, weekly, monthly - if has_key($host, 'cron'){ - $c_min = pick($host['cron'][$level]['minute'], $rsnapshot::params::cron[$level]['minute'], '*') - $c_hour = pick($host['cron'][$level]['hour'], $rsnapshot::params::cron[$level]['hour'], '*') - $c_monthday = pick($host['cron'][$level]['monthday'], $rsnapshot::params::cron[$level]['monthday'], '*') - $c_month = pick($host['cron'][$level]['month'], $rsnapshot::params::cron[$level]['month'], '*') - $c_weekday = pick($host['cron'][$level]['weekday'], $rsnapshot::params::cron[$level]['weekday'], '*') - } + if has_key($hash,cron){ + if has_key($hash[cron], $level) { + $cron = $hash[cron][$level] + if has_key($cron, minute) { + $c_min = $cron[minute] + } else { + $c_min = $rsnapshot::params::cron[$level][minute] + } + if has_key($cron, hour) { + $c_hour = $cron[hour] + } else { + $c_hour = $rsnapshot::params::cron[$level][hour] + } + if has_key($cron, monthday) { + $c_monthday = $cron[monthday] + } else { + $c_monthday = $rsnapshot::params::cron[$level][monthday] + } + if has_key($cron, month) { + $c_month = $cron[month] + } else { + $c_month = $rsnapshot::params::cron[$level][month] + } + if has_key($cron, weekday) { + $c_weekday = $cron[weekday] + } else { + $c_weekday = $rsnapshot::params::cron[$level][weekday] + } } else { - $c_min = $rsnapshot::params::cron[$level]['minute'] - $c_hour = $rsnapshot::params::cron[$level]['hour'] - $c_monthday = $rsnapshot::params::cron[$level]['monthday'] - $c_month = $rsnapshot::params::cron[$level]['month'] - $c_weekday = $rsnapshot::params::cron[$level]['weekday'] + $c_min = $rsnapshot::params::cron[$level][minute] + $c_hour = $rsnapshot::params::cron[$level][hour] + $c_monthday = $rsnapshot::params::cron[$level][monthday] + $c_month = $rsnapshot::params::cron[$level][month] + $c_weekday = $rsnapshot::params::cron[$level][weekday] } - $minute = rand_from_array($c_min, "${host}.${level}.minute") + } else { + $c_min = $rsnapshot::params::cron[$level][minute] + $c_hour = $rsnapshot::params::cron[$level][hour] + $c_monthday = $rsnapshot::params::cron[$level][monthday] + $c_month = $rsnapshot::params::cron[$level][month] + $c_weekday = $rsnapshot::params::cron[$level][weekday] + } + $minute = rand_from_array($c_min, "${host}.${level}.minute") $hour = rand_from_array($c_hour, "${host}.${level}.hour") $monthday = rand_from_array($c_monthday, "${host}.${level}.monthday") $month = rand_from_array($c_month, "${host}.${level}.month") diff --git a/manifests/params.pp b/manifests/params.pp index d4cd5c4..8765280 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -62,33 +62,33 @@ class rsnapshot::params { } $config_backup_scripts = {} $cron = { - 'hourly' => { - 'minute' => '0..59', - 'hour' => '*', # you could also do: ['21..23','0..4','5'], - 'monthday' => '*', - 'month' => '*', - 'weekday' => '*', + hourly => { + minute => '0..59', + hour => '*', # you could also do: ['21..23','0..4','5'], + monthday => '*', + month => '*', + weekday => '*', }, - 'daily' => { - 'minute' => '0..59', - 'hour' => '0..23', # you could also do: ['21..23','0..4','5'], - 'monthday' => '*', - 'month' => '*', - 'weekday' => '*', + daily => { + minute => '0..59', + hour => '0..23', # you could also do: ['21..23','0..4','5'], + monthday => '*', + month => '*', + weekday => '*', }, - 'weekly' => { - 'minute' => '0..59', - 'hour' => '0..23', # you could also do: ['21..23','0..4','5'], - 'monthday' => '*', - 'month' => '*', - 'weekday' => '0..6', + weekly => { + minute => '0..59', + hour => '0..23', # you could also do: ['21..23','0..4','5'], + monthday => '*', + month => '*', + weekday => '0..6', }, - 'monthly' => { - 'minute' => '0..59', - 'hour' => '0..23', # you could also do: ['21..23','0..4','5'], - 'monthday' => '0..28', - 'month' => '*', - 'weekday' => '*', + monthly => { + minute => '0..59', + hour => '0..23', # you could also do: ['21..23','0..4','5'], + monthday => '0..28', + month => '*', + weekday => '*', }, } }