summaryrefslogtreecommitdiff
path: root/puppet/modules/backupninja/manifests/server.pp
diff options
context:
space:
mode:
authorMicah <micah@leap.se>2016-07-12 16:46:29 -0400
committerMicah <micah@leap.se>2016-07-12 16:46:29 -0400
commit6a895ece94a86c9ccc32c9bec51413d4e4f0df8e (patch)
tree164fc1d325e2c48f5cb814d8df3405f1b9751825 /puppet/modules/backupninja/manifests/server.pp
parent1e1e25286b64790141c9627f81b50f579b13b719 (diff)
git subrepo clone https://leap.se/git/puppet_backupninja puppet/modules/backupninja
subrepo: subdir: "puppet/modules/backupninja" merged: "5268a87" upstream: origin: "https://leap.se/git/puppet_backupninja" branch: "master" commit: "5268a87" git-subrepo: version: "0.3.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "1e79595" Change-Id: I147608fbb12a35fe83642d4d031009dcc62cecee
Diffstat (limited to 'puppet/modules/backupninja/manifests/server.pp')
-rw-r--r--puppet/modules/backupninja/manifests/server.pp147
1 files changed, 147 insertions, 0 deletions
diff --git a/puppet/modules/backupninja/manifests/server.pp b/puppet/modules/backupninja/manifests/server.pp
new file mode 100644
index 00000000..49e42a0f
--- /dev/null
+++ b/puppet/modules/backupninja/manifests/server.pp
@@ -0,0 +1,147 @@
+# this define realizes all needed resources for a hosted backup
+define backupninja_server_realize($host) {
+ User <<| tag == "backupninja-$host" |>>
+ File <<| tag == "backupninja-$host" |>>
+ Ssh_authorized_key <<| tag == "backupninja-$host" |>>
+}
+
+class backupninja::server (
+ $backupdir = '/backup',
+ $backupdir_ensure = 'directory',
+ $manage_nagios = false,
+ $nagios_server = undef,
+ $nagios_warn_level = 129600,
+ $nagios_crit_level = 216000,
+) {
+
+ group { "backupninjas":
+ ensure => "present",
+ gid => 700
+ }
+
+ file { $backupdir:
+ ensure => $backupdir_ensure,
+ mode => 0710, owner => root, group => "backupninjas",
+ require => $backupdir_ensure ? {
+ 'directory' => undef,
+ default => File["$backupdir_ensure"],
+ }
+ }
+
+ if $manage_nagios {
+
+ case $nagios_server { undef: { err('Cannot manage nagios without nagios_server parameter!') } }
+
+ include nagios::nsca::client
+
+ file { "/usr/local/bin/checkbackups":
+ ensure => "present",
+ source => "puppet:///modules/backupninja/checkbackups.pl",
+ mode => 0755, owner => root, group => root,
+ }
+
+ cron { checkbackups:
+ command => "/usr/local/bin/checkbackups -d ${backupdir} -s ${nagios_server} -w ${nagios_warn_level} -c ${nagios_crit_level} | grep -v 'sent to host successfully'",
+ user => "root",
+ hour => "8-23",
+ minute => 59,
+ require => [ File["/usr/local/bin/checkbackups"], Package['nsca'] ]
+ }
+ }
+
+ # collect all resources from hosted backups
+ Backupninja_server_realize <<| tag == $::fqdn |>>
+
+ # this define allows nodes to declare a remote backup sandbox, that have to
+ # get created on the server
+ define sandbox (
+ $user = $name,
+ $host = $::fqdn,
+ $installuser = true,
+ $dir,
+ $manage_ssh_dir = true,
+ $ssh_dir = "${dir}/.ssh",
+ $authorized_keys_file = 'authorized_keys',
+ $key = false,
+ $keytype = 'dss',
+ $backupkeys = "${fileserver}/keys/backupkeys",
+ $uid = false,
+ $gid = "backupninjas",
+ $backuptag = "backupninja-${::fqdn}",
+ ) {
+
+ if !defined(Backupninja_server_realize["${::fqdn}@${host}"]) {
+ @@backupninja_server_realize { "${::fqdn}@${host}":
+ host => $::fqdn,
+ tag => $host,
+ }
+ }
+
+ if !defined(File["$dir"]) {
+ @@file { "$dir":
+ ensure => directory,
+ mode => 0750, owner => $user, group => 0,
+ tag => "$backuptag",
+ }
+ }
+
+ if $installuser {
+
+ if $manage_ssh_dir {
+ if !defined(File["$ssh_dir"]) {
+ @@file { "${ssh_dir}":
+ ensure => directory,
+ mode => 0700, owner => $user, group => 0,
+ require => [User[$user], File["$dir"]],
+ tag => "$backuptag",
+ }
+ }
+ }
+
+ if $key {
+ # $key contais ssh public key
+ if !defined(Ssh_autorized_key["$user"]) {
+ @@ssh_authorized_key{ "$user":
+ type => $keytype,
+ key => $key,
+ user => $user,
+ target => "${ssh_dir}/${authorized_keys_file}",
+ tag => "$backuptag",
+ require => User[$user],
+ }
+ }
+ }
+ else {
+ # get ssh public key exists from server
+ if !defined(File["${ssh_dir}/${authorized_keys_file}"]) {
+ @@file { "${ssh_dir}/${authorized_keys_file}":
+ ensure => present,
+ mode => 0644, owner => 0, group => 0,
+ source => "${backupkeys}/${user}_id_${keytype}.pub",
+ require => File["${ssh_dir}"],
+ tag => "$backuptag",
+ }
+ }
+ }
+
+ if !defined(User["$user"]) {
+ @@user { "$user":
+ ensure => "present",
+ uid => $uid ? {
+ false => undef,
+ default => $uid
+ },
+ gid => "$gid",
+ comment => "$user backup sandbox",
+ home => "$dir",
+ managehome => true,
+ shell => "/bin/bash",
+ password => '*',
+ require => Group['backupninjas'],
+ tag => "$backuptag"
+ }
+ }
+ }
+ }
+}
+