Commit 48711301 authored by Jerome Charaoui's avatar Jerome Charaoui

implement parameters w/ defaults in client class, removing the need for client::defaults

parent 32c44017
class backupninja::client inherits backupninja::client::defaults {
class backupninja::client (
$ensure_backupninja_version = 'installed',
$configdir = '/etc/backup.d',
$keystore = "${::fileserver}/keys/backupkeys",
$keystorefspath = false,
$keytype = 'rsa',
$keydest = '/root/.ssh',
$keyowner = 0,
$keygroup = 0,
$keymanage = true,
) {
# install client dependencies
ensure_resource('package', 'backupninja', {'ensure' => $ensure_backupninja_version})
# set up backupninja config directory
file { $configdir:
ensure => directory,
mode => 750, owner => 0, group => 0;
}
define key(
$user = false, $host = false, $createkey=false, $installkey=false,
$keyowner=false, $keygroup=false, $keystore=false, $keystorefspath='',
$keytype=false,
$keydest=false, $keydestname=false )
$user = $name,
$createkey = false,
$keymanage = $backupninja::keymanage,
$keyowner = $backupninja::keyowner,
$keygroup = $backupninja::keygroup,
$keystore= $backupninja::keystore,
$keystorefspath = $backupninja::keystorefspath,
$keytype = $backupninja::keytype,
$keydest = $backupninja::keydest,
$keydestname = "id_${backupninja::keytpe}" )
{
$real_user = $user ? {
false => $name,
default => $user
}
$real_host = $host ? {
false => $user,
default => $host
}
$install_key = $installkey ? {
false => "${backupninja::client::defaults::real_keymanage}",
default => $installkey,
}
$key_owner = $keyowner ? {
false => "${backupninja::client::defaults::real_keyowner}",
default => $keyowner,
}
$key_group = $keygroup ? {
false => "${backupninja::client::defaults::real_keygroup}",
default => $keygroup,
}
$key_store = $keystore ? {
false => "${backupninja::client::defaults::real_keystore}",
default => $keystore,
}
$key_type = $keytype ? {
'' => "${backupninja::client::defaults::real_keytype}",
false => "${backupninja::client::defaults::real_keytype}",
default => $keytype,
}
$key_dest = $keydest ? {
false => "${backupninja::client::defaults::real_keydestination}",
default => $keydest,
}
$key_dest_name = $keydestname ? {
false => "id_$key_type",
default => $keydestname,
}
$key_dest_file = "${key_dest}/${key_dest_name}"
# generate the key
if $createkey == true {
if $keystorefspath == false {
err("need to define a destination directory for sshkey creation!")
}
$ssh_keys = ssh_keygen("${keystorefspath}/${key_dest_name}")
$ssh_keys = ssh_keygen("${keystorefspath}/${keydestname}")
}
case $install_key {
true: {
if !defined(File["$key_dest"]) {
file { "$key_dest":
ensure => directory,
mode => 0700, owner => $key_owner, group => $key_group,
}
}
if !defined(File["$key_dest_file"]) {
file { "$key_dest_file":
source => "${key_store}/${key_dest_name}",
mode => 0400, owner => $key_owner, group => $key_group,
require => File["$key_dest"],
}
}
}
# deploy/manage the key
if $keymanage == true {
$keydestfile = "${keydest}/${keydestname}"
ensure_resource('file', $keydest, {
'ensure' => 'directory',
'mode' => '0700',
'owner' => $keyowner,
'group' => $keygroup
})
ensure_resource('file', $keydestfile, {
'ensure' => 'present',
'source' => "${keystore}/${keydestname}",
'mode' => '0700',
'owner' => $keyowner,
'group' => $keygroup,
'require' => 'File["$key_dest"]'
})
}
}
}
class backupninja::client::defaults {
$configdir = $cfg_override ? {
'' => "/etc/backup.d",
default => $cfg_override,
}
$real_keystore = $backupkeystore ? {
'' => "$fileserver/keys/backupkeys",
default => $backupkeystore,
}
$real_keytype = $backupkeytype ? {
'' => 'rsa',
false => 'rsa',
default => $backupkeytype,
}
$real_keydestination = $keydestination ? {
'' => '/root/.ssh',
default => $keydestination,
}
$real_keyowner = $keyowner ? {
'' => 0,
default => $keyowner,
}
$real_keygroup = $keygroup ? {
'' => 0,
default => $keygroup,
}
$real_keymanage = $keymanage ? {
'' => true,
default => $keymanage
}
$real_ssh_dir_manage = $ssh_dir_manage ? {
'' => true,
default => $ssh_dir_manage
}
if !defined(Package["backupninja"]) {
if $backupninja_ensure_version == '' { $backupninja_ensure_version = 'installed' }
package { 'backupninja':
ensure => $backupninja_ensure_version
}
}
file { $configdir:
ensure => directory,
mode => 750, owner => 0, group => 0;
}
}
......@@ -82,11 +82,11 @@ define backupninja::duplicity( $order = 90,
$destuser = false,
$desturl = false,
# configs to backupninja client
$backupkeystore = false,
$backupkeystorefspath = '',
$backupkeytype = "rsa",
$backupkeydest = false,
$backupkeydestname = false,
$backupkeystore = $backupninja::keystore,
$backupkeystorefspath = $backupninja::keystorefspath,
$backupkeytype = $backupninja::keytype,
$backupkeydest = $backupninja::keydest,
$backupkeydestname = $backupninja::keydestname,
# options to backupninja server sandbox
$ssh_dir_manage = true,
$ssh_dir = false,
......@@ -100,9 +100,6 @@ define backupninja::duplicity( $order = 90,
# install client dependencies
ensure_resource('package', 'duplicity', {'ensure' => $ensure_duplicity_version})
# the client with configs for this machine
include backupninja::client::duplicity
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 $password { false: { err("a password is necessary either to unlock the GPG key, or for symmetric encryption!") } }
......@@ -135,13 +132,13 @@ define backupninja::duplicity( $order = 90,
}
# the backupninja rule for this duplicity backup
file { "${backupninja::client::defaults::configdir}/${order}_${name}.dup":
file { "${backupninja::configdir}/${order}_${name}.dup":
ensure => $ensure,
content => template('backupninja/dup.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::configdir}"]
}
}
......@@ -23,23 +23,22 @@ define backupninja::labelmount($order = 10,
$label,
$dest
) {
include backupninja::client::defaults
file { "${backupninja::client::defaults::configdir}/${order}_${name}.labelmount":
file { "${backupninja::configdir}/${order}_${name}.labelmount":
ensure => $ensure,
content => template('backupninja/labelmount.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::configdir}"]
}
file { "${backupninja::client::defaults::configdir}/99_${name}.umount":
file { "${backupninja::configdir}/99_${name}.umount":
ensure => $ensure,
content => template('backupninja/umount.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::configdir}"]
}
# Copy over the handler scripts themselves, since they're not in the
......
......@@ -32,12 +32,12 @@ define backupninja::maildir(
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!") } }
file { "${backupninja::client::defaults::configdir}/${order}_${name}.maildir":
file { "${backupninja::configdir}/${order}_${name}.maildir":
ensure => $ensure,
content => template('backupninja/maildir.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::configdir}"]
}
}
......@@ -27,13 +27,12 @@ define backupninja::mysql(
default => $configfile,
}
include backupninja::client::defaults
file { "${backupninja::client::defaults::configdir}/${order}_${name}.mysql":
file { "${backupninja::configdir}/${order}_${name}.mysql":
ensure => $ensure,
content => template('backupninja/mysql.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::configdir}"]
}
}
......@@ -16,14 +16,12 @@
define backupninja::pgsql(
$order = 10, $ensure = present, $databases = 'all', $backupdir = "/var/backups/postgres", $compress = true, $vsname = false)
{
include backupninja::client::defaults
file { "${backupninja::client::defaults::configdir}/${order}_${name}.pgsql":
file { "${backupninja::configdir}/${order}_${name}.pgsql":
ensure => $ensure,
content => template('backupninja/pgsql.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::configdir}"]
}
}
......@@ -26,7 +26,8 @@ define backupninja::rdiff(
"/home", "/usr/local/*bin", "/var/lib/dpkg/status*" ],
$vsinclude = false, $keep = 30, $sshoptions = false, $options = '--force', $ssh_dir_manage = true,
$ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true, $key = false,
$backuptag = false, $backupkeytype = "rsa", $backupkeystore = false, $extras = false, $nagios2_description = 'backups')
$backuptag = false, $backupkeytype = $backupninja::keytype, $backupkeystore = $backupninja::keystore,
$extras = false, $nagios2_description = 'backups')
{
# install client dependencies
ensure_resource('package', 'rdiff-backup', {'ensure' => $ensure_rdiffbackup_version})
......@@ -61,13 +62,13 @@ define backupninja::rdiff(
}
file { "${backupninja::client::defaults::configdir}/${order}_${name}.rdiff":
file { "${backupninja::configdir}/${order}_${name}.rdiff":
ensure => $ensure,
content => template('backupninja/rdiff.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::configdir}"]
}
}
......@@ -6,7 +6,7 @@ define backupninja::rsync(
$user = false, $home = false, $host = false,
$ssh_dir_manage = true, $ssh_dir = false, $authorized_keys_file = false,
$installuser = true, $installkey = true, $key = false, $backuptag = false,
$home = false, $backupkeytype = "rsa", $backupkeystore = false, $extras = false,
$home = false, $backupkeytype = $backupninja::keytype, $backupkeystore = $backupninja::keystore, $extras = false,
$nagios2_description = 'backups', $subfolder = 'rsync',
$log = false, $partition = false, $fscheck = false, $read_only = false,
......@@ -78,12 +78,12 @@ define backupninja::rsync(
}
}
file { "${backupninja::client::defaults::configdir}/${order}_${name}.rsync":
file { "${backupninja::configdir}/${order}_${name}.rsync":
ensure => $ensure,
content => template('backupninja/rsync.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::configdir}"]
}
}
......@@ -14,13 +14,12 @@ define backupninja::sh($order = 50,
$ensure = present,
$command_string
) {
include backupninja::client::defaults
file { "${backupninja::client::defaults::configdir}/${order}_${name}.sh":
file { "${backupninja::configdir}/${order}_${name}.sh":
ensure => $ensure,
content => template('backupninja/sh.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::configdir}"]
}
}
......@@ -17,13 +17,12 @@ define backupninja::svn($order = 20,
$tmp = '/var/backups/svn.tmp',
$vsname = false
) {
include backupninja::client::defaults
file { "${backupninja::client::defaults::configdir}/${order}_${name}.svn":
file { "${backupninja::configdir}/${order}_${name}.svn":
ensure => $ensure,
content => template('backupninja/svn.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::configdir}"]
}
}
......@@ -26,7 +26,6 @@ define backupninja::sys($order = 30,
$doluks = false,
$dolvm = false
) {
include backupninja::client::defaults
# install client dependencies
case $operatingsystem {
......@@ -37,12 +36,12 @@ define backupninja::sys($order = 30,
default: {}
}
file { "${backupninja::client::defaults::configdir}/${order}_${name}.sys":
file { "${backupninja::configdir}/${order}_${name}.sys":
ensure => $ensure,
content => template('backupninja/sys.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backupninja::client::defaults::configdir}"]
require => File["${backupninja::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