Commit b432d94f authored by Silvio Rhatto's avatar Silvio Rhatto

New backupninja::client::defaults to avoid duplicates.

Adding part of client.pp code into new class
backupninja::client::defaults in an attempt to avoid duplicate
definitions inside backupninja::client::key.
parent f96267fe
class backupninja::client { class backupninja::client::defaults {
$configdir = $cfg_override ? { $configdir = $cfg_override ? {
'' => "/etc/backup.d", '' => "/etc/backup.d",
default => $cfg_override, default => $cfg_override,
...@@ -38,6 +38,9 @@ class backupninja::client { ...@@ -38,6 +38,9 @@ class backupninja::client {
file { $configdir: file { $configdir:
ensure => directory ensure => directory
} }
}
class backupninja::client inherits backupninja::client::defaults {
define key( define key(
$user = false, $host = false, $installkey=false, $keyowner=false, $user = false, $host = false, $installkey=false, $keyowner=false,
$keygroup=false, $keystore=false, $keytype=false) $keygroup=false, $keystore=false, $keytype=false)
...@@ -51,40 +54,40 @@ class backupninja::client { ...@@ -51,40 +54,40 @@ class backupninja::client {
default => $host default => $host
} }
$install_key = $installkey ? { $install_key = $installkey ? {
false => "${backupninja::client::real_keymanage}", false => "${backupninja::client::defaults::real_keymanage}",
default => $installkey, default => $installkey,
} }
$key_owner = $keyowner ? { $key_owner = $keyowner ? {
false => "${backupninja::client::real_keyowner}", false => "${backupninja::client::defaults::real_keyowner}",
default => $keyowner, default => $keyowner,
} }
$key_group = $keygroup ? { $key_group = $keygroup ? {
false => "${backupninja::client::real_keygroup}", false => "${backupninja::client::defaults::real_keygroup}",
default => $keygroup, default => $keygroup,
} }
$key_store = $keystore ? { $key_store = $keystore ? {
false => "${backupninja::client::real_keystore}", false => "${backupninja::client::defaults::real_keystore}",
default => $keystore, default => $keystore,
} }
$key_type = $keytype ? { $key_type = $keytype ? {
'' => "${backupninja::client::real_keytype}", '' => "${backupninja::client::defaults::real_keytype}",
false => "${backupninja::client::real_keytype}", false => "${backupninja::client::defaults::real_keytype}",
default => $keytype, default => $keytype,
} }
case $install_key { case $install_key {
true: { true: {
if !defined(File["${backupninja::client::real_keydestination}"]) { if !defined(File["${backupninja::client::defaults::real_keydestination}"]) {
file { "${backupninja::client::real_keydestination}": file { "${backupninja::client::defaults::real_keydestination}":
ensure => directory, ensure => directory,
mode => 0700, owner => $key_owner, group => $key_group, mode => 0700, owner => $key_owner, group => $key_group,
} }
} }
if !defined(File["${backupninja::client::real_keydestination/id_${key_type}"]) { if !defined(File["${backupninja::client::defaults::real_keydestination/id_${key_type}"]) {
file { "${backupninja::client::real_keydestination}/id_${key_type}": file { "${backupninja::client::defaults::real_keydestination}/id_${key_type}":
source => "${key_store}/${real_user}_id_${key_type}", source => "${key_store}/${real_user}_id_${key_type}",
mode => 0400, owner => $key_owner, group => $key_group, mode => 0400, owner => $key_owner, group => $key_group,
require => File["${backupninja::client::real_keydestination}"], require => File["${backupninja::client::defaults::real_keydestination}"],
} }
} }
} }
...@@ -92,7 +95,7 @@ class backupninja::client { ...@@ -92,7 +95,7 @@ class backupninja::client {
} }
} }
class backupninja::client::maildir inherits backupninja::client { class backupninja::client::maildir inherits backupninja::client::defaults {
if !defined(Package["rsync"]) { if !defined(Package["rsync"]) {
if $rsync_ensure_version == '' { $rsync_ensure_version = 'installed' } if $rsync_ensure_version == '' { $rsync_ensure_version = 'installed' }
...@@ -102,7 +105,7 @@ class backupninja::client::maildir inherits backupninja::client { ...@@ -102,7 +105,7 @@ class backupninja::client::maildir inherits backupninja::client {
} }
} }
class backupninja::client::rdiff_backup inherits backupninja::client { class backupninja::client::rdiff_backup inherits backupninja::client::defaults {
if !defined(Package["rdiff-backup"]) { if !defined(Package["rdiff-backup"]) {
if $rdiff_backup_ensure_version == '' { $rdiff_backup_ensure_version = 'installed' } if $rdiff_backup_ensure_version == '' { $rdiff_backup_ensure_version = 'installed' }
...@@ -112,7 +115,7 @@ class backupninja::client::rdiff_backup inherits backupninja::client { ...@@ -112,7 +115,7 @@ class backupninja::client::rdiff_backup inherits backupninja::client {
} }
} }
class backupninja::client::duplicity inherits backupninja::client { class backupninja::client::duplicity inherits backupninja::client::defaults {
if !defined(Package["duplicity"]) { if !defined(Package["duplicity"]) {
if $duplicity_ensure_version == '' { $duplicity_ensure_version = 'installed' } if $duplicity_ensure_version == '' { $duplicity_ensure_version = 'installed' }
......
...@@ -90,7 +90,7 @@ define backupninja::duplicity( $order = 90, ...@@ -90,7 +90,7 @@ define backupninja::duplicity( $order = 90,
$installkey = true ) { $installkey = true ) {
# the client with configs for this machine # the client with configs for this machine
include backupninja::client include backupninja::client::defaults
case $desthost { false: { err("need to define a destination host for remote backups!") } } case $desthost { false: { err("need to define a destination host for remote backups!") } }
case $destdir { false: { err("need to define a destination directory for remote backups!") } } case $destdir { false: { err("need to define a destination directory for remote backups!") } }
...@@ -119,13 +119,13 @@ define backupninja::duplicity( $order = 90, ...@@ -119,13 +119,13 @@ define backupninja::duplicity( $order = 90,
} }
# the backupninja rule for this duplicity backup # the backupninja rule for this duplicity backup
file { "${backupninja::client::configdir}/${order}_${name}.dup": file { "${backupninja::client::defaults::configdir}/${order}_${name}.dup":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/dup.conf.erb'), content => template('backupninja/dup.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${backupninja::client::configdir}"] require => File["${backupninja::client::defaults::configdir}"]
} }
} }
...@@ -23,23 +23,23 @@ define backupninja::labelmount($order = 10, ...@@ -23,23 +23,23 @@ define backupninja::labelmount($order = 10,
$label, $label,
$dest $dest
) { ) {
include backupninja::client include backupninja::client::defaults
file { "${backupninja::client::configdir}/${order}_${name}.labelmount": file { "${backupninja::client::defaults::configdir}/${order}_${name}.labelmount":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/labelmount.conf.erb'), content => template('backupninja/labelmount.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${backupninja::client::configdir}"] require => File["${backupninja::client::defaults::configdir}"]
} }
file { "${backupninja::client::configdir}/99_${name}.umount": file { "${backupninja::client::defaults::configdir}/99_${name}.umount":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/umount.conf.erb'), content => template('backupninja/umount.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${backupninja::client::configdir}"] require => File["${backupninja::client::defaults::configdir}"]
} }
# Copy over the handler scripts themselves, since they're not in the # Copy over the handler scripts themselves, since they're not in the
......
...@@ -22,7 +22,7 @@ define backupninja::maildir( ...@@ -22,7 +22,7 @@ define backupninja::maildir(
$remove = false, $multiconnection = yes, $keepdaily='4', $keepweekly='2', $remove = false, $multiconnection = yes, $keepdaily='4', $keepweekly='2',
$keepmonthly='2') $keepmonthly='2')
{ {
include backupninja::client include backupninja::client::defaults
case $srcdir { false: { err("need to define a source directory to backup!") } } case $srcdir { false: { err("need to define a source directory to backup!") } }
case $destdir { false: { err("need to define a destination directory to backup!") } } case $destdir { false: { err("need to define a destination directory to backup!") } }
...@@ -30,12 +30,12 @@ define backupninja::maildir( ...@@ -30,12 +30,12 @@ define backupninja::maildir(
case $destuser { false: { err("need to define a destination user for backups!") } } case $destuser { false: { err("need to define a destination user for backups!") } }
case $destid_file { false: { err("need to define a ssh key id file to use!") } } case $destid_file { false: { err("need to define a ssh key id file to use!") } }
file { "${backupninja::client::configdir}/${order}_${name}.maildir": file { "${backupninja::client::defaults::configdir}/${order}_${name}.maildir":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/maildir.conf.erb'), content => template('backupninja/maildir.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${backupninja::client::configdir}"] require => File["${backupninja::client::defaults::configdir}"]
} }
} }
...@@ -20,13 +20,13 @@ define backupninja::mysql( ...@@ -20,13 +20,13 @@ define backupninja::mysql(
$sqldump = false, $compress = false, $configfile = '/etc/mysql/debian.cnf', $sqldump = false, $compress = false, $configfile = '/etc/mysql/debian.cnf',
$vsname = false) $vsname = false)
{ {
include backupninja::client include backupninja::client::defaults
file { "${backupninja::client::configdir}/${order}_${name}.mysql": file { "${backupninja::client::defaults::configdir}/${order}_${name}.mysql":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/mysql.conf.erb'), content => template('backupninja/mysql.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${backupninja::client::configdir}"] require => File["${backupninja::client::defaults::configdir}"]
} }
} }
...@@ -27,7 +27,7 @@ define backupninja::rdiff( ...@@ -27,7 +27,7 @@ define backupninja::rdiff(
$ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true, $ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true,
$backuptag = false, $home = false, $backupkeytype = "rsa") $backuptag = false, $home = false, $backupkeytype = "rsa")
{ {
include backupninja::client include backupninja::client::defaults
case $directory { false: { err("need to define a directory for where the backups should go!") } } case $directory { false: { err("need to define a directory for where the backups should go!") } }
...@@ -55,13 +55,13 @@ define backupninja::rdiff( ...@@ -55,13 +55,13 @@ define backupninja::rdiff(
} }
} }
} }
file { "${backupninja::client::configdir}/${order}_${name}.rdiff": file { "${backupninja::client::defaults::configdir}/${order}_${name}.rdiff":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/rdiff.conf.erb'), content => template('backupninja/rdiff.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${backupninja::client::configdir}"] require => File["${backupninja::client::defaults::configdir}"]
} }
} }
...@@ -14,13 +14,13 @@ define backupninja::sh($order = 50, ...@@ -14,13 +14,13 @@ define backupninja::sh($order = 50,
$ensure = present, $ensure = present,
$command_string $command_string
) { ) {
include backupninja::client include backupninja::client::defaults
file { "${backupninja::client::configdir}/${order}_${name}.sh": file { "${backupninja::client::defaults::configdir}/${order}_${name}.sh":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/sh.conf.erb'), content => template('backupninja/sh.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${backupninja::client::configdir}"] require => File["${backupninja::client::defaults::configdir}"]
} }
} }
...@@ -17,13 +17,13 @@ define backupninja::svn($order = 20, ...@@ -17,13 +17,13 @@ define backupninja::svn($order = 20,
$tmp = '/var/backups/svn.tmp', $tmp = '/var/backups/svn.tmp',
$vsname = false $vsname = false
) { ) {
include backupninja::client include backupninja::client::defaults
file { "${backupninja::client::configdir}/${order}_${name}.svn": file { "${backupninja::client::defaults::configdir}/${order}_${name}.svn":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/svn.conf.erb'), content => template('backupninja/svn.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${backupninja::client::configdir}"] require => File["${backupninja::client::defaults::configdir}"]
} }
} }
...@@ -22,13 +22,13 @@ define backupninja::sys($order = 30, ...@@ -22,13 +22,13 @@ define backupninja::sys($order = 30,
$hardwarefile = '/var/backups/hardware.txt', $hardwarefile = '/var/backups/hardware.txt',
$dohwinfo = yes $dohwinfo = yes
) { ) {
include backupninja::client include backupninja::client::defaults
file { "${backupninja::client::configdir}/${order}_${name}.sys": file { "${backupninja::client::defaults::configdir}/${order}_${name}.sys":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/sys.conf.erb'), content => template('backupninja/sys.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${backupninja::client::configdir}"] require => File["${backupninja::client::defaults::configdir}"]
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment