1
0
mirror of https://github.com/krislamo/puppet-rsnapshot synced 2024-12-16 09:40:35 +00:00

some code cleanup for better readability

This commit is contained in:
Norbert Varzariu 2015-12-19 21:39:36 +01:00
parent fa88ccb1cb
commit 53ead018cb

View File

@ -16,30 +16,17 @@ 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 }
# }
#
# custom function, if only a hostname is given as a param, this is an empty hash
# the next loop would break as puppet does not allow to reassign variables
# the function checks $hosts for elements like:
# { foo => } and converts those to { foo => {} }
$hosts_clean = assert_empty_hash($hosts)
notify {"Hosts is: $hosts ": }
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)
$backup = pick($hash['backup'], $rsnapshot::params::config_backup)
$backup_defaults = pick($hash['backup_defaults'], $rsnapshot::params::config_backup_defaults)
if $backup_defaults {
$backups = merge($backup, $rsnapshot::params::config_backup)
} 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)
@ -59,10 +46,7 @@ class rsnapshot::config (
$linux_lvm_vgpath = pick_undef($hash['linux_lvm_vgpath'], $rsnapshot::params::config_linux_lvm_vgpath)
$linux_lvm_mountpath = pick_undef($hash['linux_lvm_mountpath'], $rsnapshot::params::config_linux_lvm_mountpath)
$no_create_root = pick_undef($hash['no_create_root'], $rsnapshot::params::config_no_create_root)
notice("no_create_root for $host is $no_create_root ")
$lockfile = "${lockpath}/${host}.pid"
$logpath = pick($hash['logpath'], $rsnapshot::logpath, $rsnapshot::params::config_logpath)
$logfile = "${logpath}/${host}.log"
$verbose = pick($hash['verbose'], $rsnapshot::params::config_verbose)
$loglevel = pick($hash['loglevel'], $rsnapshot::params::config_loglevel)
$stop_on_stale_lockfile = pick_undef($hash['stop_on_stale_lockfile'], $rsnapshot::params::config_stop_on_stale_lockfile)
@ -71,35 +55,49 @@ class rsnapshot::config (
$ssh_args = pick_undef($hash['ssh_args'], $rsnapshot::params::config_ssh_args)
$du_args = pick_undef($hash['du_args'], $rsnapshot::params::config_du_args)
$one_fs = pick_undef($hash['one_fs'], $rsnapshot::params::config_one_fs)
# one of both interval or retain must be present
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
$retain = pick_undef($hash['retain'], $rsnapshot::params::config_retain)
notice("interval for $host is $interval ")
if ! ($interval and $retain ) {
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
}
$include = pick_undef($hash['include'], $rsnapshot::params::config_include)
$exclude = pick_undef($hash['exclude'], $rsnapshot::params::config_exclude)
$include_file = pick_undef($hash['include_file'], $rsnapshot::params::config_include_file)
$exclude_file = pick($hash['exclude_file'], $rsnapshot::params::config_exclude_file, "${conf_d}/${host}.exclude")
$link_dest = pick_undef($hash['link_dest'], $rsnapshot::params::config_link_dest)
if $link_dest { $link_dest_num = bool2num($link_dest) }
$sync_first = pick_undef($hash['sync_first'], $rsnapshot::params::config_sync_first)
if $sync_first { $sync_first_num = bool2num($sync_first) }
$rsync_numtries = pick_undef($hash['rsync_numtries'], $rsnapshot::params::config_rsync_numtries)
$use_lazy_deletes = pick_undef($hash['use_lazy_deletes'], $rsnapshot::params::config_use_lazy_deletes)
if $use_lazy_deletes { $use_lazy_deletes_num = bool2num($use_lazy_deletes) }
$rsync_numtries = pick_undef($hash['rsync_numtries'], $rsnapshot::params::config_rsync_numtries)
$backup_scripts = pick_undef($hash['backup_scripts'], $rsnapshot::params::config_backup_scripts)
$snapshot_dir = "${config_snapshot_root}/${host}"
$config = "${conf_d}/${host}.rsnapshot.conf"
$lockfile = "${lockpath}/${host}.pid"
$logfile = "${logpath}/${host}.log"
# merge the backup hashes to one if backup_default is set (defaults to true)
if $backup_defaults {
$backups = merge($backup, $rsnapshot::params::config_backup)
} else {
$backups = $backup
}
file { $config:
# one of both interval or retain must be present
if ! ( $interval and $retain ) {
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
}
# rsnapshot wants numeric values
if $link_dest {
$link_dest_num = bool2num($link_dest)
}
if $sync_first {
$sync_first_num = bool2num($sync_first)
}
if $use_lazy_deletes {
$use_lazy_deletes_num = bool2num($use_lazy_deletes)
}
file { $exclude_file:
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
}
file { $config:
content => template('rsnapshot/rsnapshot.erb')
}
}