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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# 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 {
$real_backupdir = $backupdir ? {
'' => "/backup",
default => $backupdir,
}
$real_usermanage = $usermanage ? {
'' => 'doit',
default => $usermanage
}
$real_backupserver_tag = $backupserver_tag ? {
'' => $fqdn,
default => $backupserver_tag
}
group { "backupninjas":
ensure => "present",
gid => 700
}
file { "$real_backupdir":
ensure => "directory",
mode => 0710, owner => root, group => "backupninjas"
}
if $nagios_server {
if !defined(Package["nsca"]) {
package { "nsca":
ensure => installed;
}
}
file { "/usr/local/bin/checkbackups":
ensure => "present",
source => "puppet://$servername/backupninja/checkbackups.pl",
mode => 0755, owner => root, group => root,
}
cron { checkbackups:
command => "/usr/local/bin/checkbackups -d $real_backupdir | /usr/sbin/send_nsca -H $nagios_server -c /etc/send_nsca.cfg | 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 == "$real_backupserver_tag" |>>
if !defined(Package["rsync"]) {
if $rsync_ensure_version == '' { $rsync_ensure_version = 'installed' }
package { 'rsync':
ensure => $rsync_ensure_version,
}
}
# this define allows nodes to declare a remote backup sandbox, that have to
# get created on the server
define sandbox(
$user = false, $host = false, $installuser = true, $dir = false, $manage_ssh_dir = true,
$ssh_dir = false, $authorized_keys_file = false, $key = false, $keytype = 'dss', $backupkeys = false, $uid = false,
$gid = "backupninjas", $backuptag = false, $nagios2_description = "backups")
{
$real_user = $user ? {
false => $name,
default => $user,
'' => $name,
}
$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,
}
$real_ssh_dir = $ssh_dir ? {
false => "${real_dir}/.ssh",
default => $ssh_dir,
}
$real_authorized_keys_file = $authorized_keys_file ? {
false => "authorized_keys",
default => $authorized_keys_file,
}
$real_backuptag = $backuptag ? {
false => "backupninja-$fqdn",
default => $backuptag,
}
$real_nagios2_description = $nagios2_description ? {
false => "backups",
default => $nagios2_description,
}
if $nagios_server {
# configure a passive service check for backups
nagios2::passive_service { "backups-${name}": nagios2_host_name => $real_host, nagios2_description => $real_nagios2_description, servicegroups => "backups" }
}
if !defined(Backupninja_server_realize["${fqdn}@${real_host}"]) {
# this defines just maps that $real_host host backups for $fdqn
@@backupninja_server_realize { "${fqdn}@${real_host}":
host => $fqdn,
tag => $real_host,
}
}
if !defined(File["$real_dir"]) {
@@file { "$real_dir":
ensure => directory,
mode => 0750, owner => $real_user, group => 0,
tag => "$real_backuptag",
}
}
case $installuser {
true: {
case $manage_ssh_dir {
true: {
if !defined(File["$real_ssh_dir"]) {
@@file { "${real_ssh_dir}":
ensure => directory,
mode => 0700, owner => $real_user, group => 0,
require => [User[$real_user], File["$real_dir"]],
tag => "$real_backuptag",
}
}
}
}
case $key {
false: {
if !defined(File["${real_ssh_dir}/${real_authorized_keys_file}"]) {
@@file { "${real_ssh_dir}/${real_authorized_keys_file}":
ensure => present,
mode => 0644, owner => 0, group => 0,
source => "$real_backupkeys/${real_user}_id_${keytype}.pub",
require => File["${real_ssh_dir}"],
tag => "$real_backuptag",
}
}
}
default: {
if !defined(Ssh_autorized_key["$real_user"]) {
@@ssh_authorized_key{ "$real_user":
type => $keytype,
key => $key,
user => $real_user,
target => "${real_ssh_dir}/${real_authorized_keys_file}",
tag => "$real_backuptag",
require => User[$real_user],
}
}
}
}
case $uid {
false: {
if !defined(User["$real_user"]) {
@@user { "$real_user":
ensure => "present",
gid => "$gid",
comment => "$real_user backup sandbox",
home => "$real_dir",
managehome => true,
shell => "/bin/sh",
password => '*',
require => Group['backupninjas'],
tag => "$real_backuptag"
}
}
}
default: {
if !defined(User["$real_user"]) {
@@user { "$real_user":
ensure => "present",
uid => "$uid",
gid => "$gid",
comment => "$real_user backup sandbox",
home => "$real_dir",
managehome => true,
shell => "/bin/sh",
password => '*',
require => Group['backupninjas'],
tag => "$real_backuptag"
}
}
}
}
}
}
}
}
|