summaryrefslogtreecommitdiff
path: root/manifests/server.pp
blob: c08b33d949063cf21f1c3e52cd39e08a4f213009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class backupninja::server {
  $real_backupdir = $backupdir ? {
    '' => "/backup",
    default => $backupdir,
  }
  $real_backupserver_tag = $backupserver_tag ? {
    '' => $fqdn,
    default => $backupserver_tag
  }
  group { "backupninjas":
    ensure => "present",
    gid => 700
  }
  file { "$real_backupdir":
    ensure => "directory",
    mode => 710, owner => root, group => "backupninjas"
  }
  User <<| tag == "backupninja-$real_backupserver_tag" |>>
  File <<| tag == "backupninja-$real_backupserver_tag" |>>

  # this define allows nodes to declare a remote backup sandbox, that have to
  # get created on the server
  define sandbox($host = false, $dir = false, $backupkeys = false, $uid = false, $gid = "backupninjas") {
    $real_host = $host ? {
      false => $fqdn,
      default => $host,
    }
    $real_backupkeys = $backupkeys ? {
      false => "$fileserver/keys/backupkeys",
      default => $backupkeys,
    }
    $real_dir = $dir ? {
      false => "${backupninja::server::real_backupdir}/$fqdn",
      default => $dir,
    }
    @@file { "$real_dir":
      ensure => directory,
      mode => 750, owner => $name, group => 0,
      tag => "backupninja-$real_host",
    }
    @@file { "$real_dir/.ssh":
      ensure => directory,
      mode => 700, owner => $name, group => 0,
      require => File["$real_dir"],
      tag => "backupninja-$real_host",
    }
    @@file { "$real_dir/.ssh/authorized_keys":
      ensure => present,
      mode => 644, owner => 0, group => 0,
      source => "$real_backupkeys/${name}_id_rsa.pub",
      require => File["$real_dir/.ssh"],
      tag => "backupninja-$real_host",
    }
    
    case $uid {
      false: {
        @@user { "$name":
          ensure  => "present",
          gid     => "$gid",
          comment => "$name backup sandbox",
          home    => "$real_dir",
          managehome => true,
          shell   => "/bin/sh",
          password => '*',
          require => Group['backupninjas'],
          tag => "backupninja-$real_host"
        }
      }
      default: {
        @@user { "$name":
          ensure  => "present",
          uid     => "$uid",
          gid     => "$gid",
          comment => "$name backup sandbox",
          home    => "$real_dir",
          managehome => true,
          shell   => "/bin/sh",
          password => '*',
          require => Group['backupninjas'],
          tag => "backupninja-$real_host"
        }
      }
    }
  }
}