162 lines
4.3 KiB
Puppet
162 lines
4.3 KiB
Puppet
|
|
# Add client into BackupPC server
|
|
#
|
|
# === Parameters
|
|
#
|
|
# $name:
|
|
# Client hostname
|
|
#
|
|
# $ensure:
|
|
# If set to present client will be added and if absent
|
|
# it will be removed from server.
|
|
#
|
|
# $operatingsystem:
|
|
# Operatingsystem of client. Used to find correct client
|
|
# configuration. Defaults to "default".
|
|
#
|
|
define backuppc::manualclient($ensure = "present", $operatingsystem = "default") {
|
|
|
|
@@file { "/etc/BackupPC/pc/${name}.pl":
|
|
ensure => "${ensure}",
|
|
source => [ "puppet:///files/backuppc/${fqdn}.pl",
|
|
"puppet:///files/backuppc/${operatingsystem}.pl",
|
|
"puppet:///files/backuppc/default.pl",
|
|
"puppet:///backuppc/default.pl", ],
|
|
mode => 0640,
|
|
owner => root,
|
|
group => backuppc,
|
|
tag => "backuppc",
|
|
require => File["/etc/BackupPC/pc"],
|
|
notify => Exec["generate-backuppc-hosts"],
|
|
}
|
|
|
|
}
|
|
|
|
# Install host into BackupPC server as client.
|
|
#
|
|
class backuppc::client {
|
|
|
|
backuppc::manualclient { "${fqdn}":
|
|
ensure => present,
|
|
operatingsystem => "${operatingsystem}",
|
|
}
|
|
|
|
Ssh_authorized_key <<| tag == "backuppc" |>>
|
|
|
|
}
|
|
|
|
# Install BackupPC server and add defined clients.
|
|
#
|
|
class backuppc::server {
|
|
|
|
include user::system
|
|
realize(User["backuppc"], Group["backuppc"])
|
|
|
|
package { "BackupPC":
|
|
ensure => installed,
|
|
require => [ User["backuppc"],
|
|
Group["backuppc"], ],
|
|
}
|
|
|
|
if $backuppc_datadir {
|
|
file { "${backuppc_datadir}":
|
|
ensure => directory,
|
|
mode => 0750,
|
|
owner => backuppc,
|
|
group => root,
|
|
require => Package["BackupPC"],
|
|
}
|
|
|
|
file { "/var/lib/BackupPC":
|
|
ensure => "${backuppc_datadir}",
|
|
force => true,
|
|
backup => ".orig",
|
|
require => File["${backuppc_datadir}"],
|
|
before => [ Exec["generate-backuppc-sshkey"],
|
|
Service["backuppc"], ],
|
|
}
|
|
}
|
|
|
|
apache::configfile { "BackupPC.conf":
|
|
http => false,
|
|
content => template("backuppc/BackupPC.conf.erb"),
|
|
require => Package["BackupPC"],
|
|
}
|
|
file { "/usr/share/BackupPC/sbin/BackupPC_Admin":
|
|
ensure => present,
|
|
mode => 4750,
|
|
owner => "backuppc",
|
|
group => "httpsd",
|
|
require => Package["BackupPC"],
|
|
}
|
|
|
|
file { "/etc/BackupPC/config.pl":
|
|
ensure => present,
|
|
source => "puppet:///files/backuppc/config.pl",
|
|
mode => 0440,
|
|
owner => "backuppc",
|
|
group => "backuppc",
|
|
require => Package["BackupPC"],
|
|
notify => Service["backuppc"],
|
|
}
|
|
|
|
file { "/etc/BackupPC/hosts.in":
|
|
ensure => present,
|
|
source => [ "puppet:///files/backuppc/hosts.in",
|
|
"puppet:///backuppc/hosts.in", ],
|
|
mode => 0644,
|
|
owner => root,
|
|
group => backuppc,
|
|
require => Package["BackupPC"],
|
|
notify => Exec["generate-backuppc-hosts"],
|
|
}
|
|
|
|
file { "/etc/BackupPC/pc":
|
|
ensure => directory,
|
|
purge => true,
|
|
force => true,
|
|
recurse => true,
|
|
mode => 0640,
|
|
owner => root,
|
|
group => backuppc,
|
|
source => "puppet:///custom/empty",
|
|
require => Package["BackupPC"],
|
|
notify => Exec["generate-backuppc-hosts"],
|
|
}
|
|
|
|
exec { "generate-backuppc-hosts":
|
|
command => '(cat /etc/BackupPC/hosts.in ; find /etc/BackupPC/pc/ -name \*.pl -exec basename {} .pl \; | sed -e "s/$/ 0 adm/") > /etc/BackupPC/hosts',
|
|
path => "/bin:/usr/bin:/sbin:/usr/sbin",
|
|
refreshonly => true,
|
|
require => File["/etc/BackupPC/hosts.in"],
|
|
notify => Service["backuppc"],
|
|
}
|
|
|
|
File <<| tag == "backuppc" |>>
|
|
|
|
service { "backuppc":
|
|
ensure => running,
|
|
enable => true,
|
|
require => Package["BackupPC"],
|
|
}
|
|
|
|
exec { "generate-backuppc-sshkey":
|
|
command => "ssh-keygen -q -t rsa -f /var/lib/BackupPC/.ssh/id_rsa",
|
|
path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin",
|
|
user => "backuppc",
|
|
require => [ User["backuppc"],
|
|
Package["BackupPC"], ],
|
|
creates => [ "/var/lib/BackupPC/.ssh/id_rsa",
|
|
"/var/lib/BackupPC/.ssh/id_rsa.pub", ],
|
|
}
|
|
|
|
@@ssh_authorized_key { "backuppc":
|
|
ensure => present,
|
|
key => $backuppc_sshkey,
|
|
type => "ssh-rsa",
|
|
user => "root",
|
|
target => "/root/.ssh/authorized_keys",
|
|
tag => "backuppc",
|
|
}
|
|
|
|
}
|