bacula::client -- support present/absent
[mirror/dsa-puppet.git] / modules / bacula / manifests / client.pp
1 # our bacula client configuration
2 #
3 # this mostly configures the file daemon, but also firewall rules and
4 # fragments to sent to the other servers.
5 class bacula::client(
6   Enum['present', 'absent'] $ensure = getfromhash($site::nodeinfo, 'not-bacula-client') ? { true => 'absent', default => 'present' },
7   # Enum['present', 'absent'] $ensure = defined(Class["bacula::not_a_client"]) ? { true => 'absent', default => 'present' },
8 ) inherits bacula {
9   $package_ensure = $ensure ? { 'present' => 'installed', 'absent' => 'purged' }
10   $service_ensure = $ensure ? { 'present' => 'running', 'absent'  => 'stopped' }
11   $service_enable = $ensure ? { 'present' => true, 'absent' => false }
12   $reverse_ensure = $ensure ? { 'present' => 'absent', 'absent' => 'present' }
13
14   if $ensure == 'present' {
15     @@bacula::storage_per_node { $::fqdn: }
16
17     @@bacula::node { $::fqdn:
18       bacula_client_port => $bacula::bacula_client_port,
19     }
20
21     @@concat::fragment { "bacula-dsa-client-list::$fqdn":
22       target  => $bacula::bacula_dsa_client_list ,
23       content => @("EOF"),
24           ${fqdn}
25           | EOF
26       tag     => $bacula::tag_bacula_dsa_client_list,
27     }
28   } elsif $ensure == 'absent' {
29     file { '/etc/bacula':
30       ensure  => absent,
31       purge   => true,
32       force   => true,
33       recurse => true;
34     }
35   }
36
37   package { ['bacula-fd', 'bacula-common']:
38     ensure => $package_ensure
39   }
40
41   service { 'bacula-fd':
42     ensure    => $service_ensure,
43     enable    => $service_enable,
44     hasstatus => true,
45     require   => Package['bacula-fd']
46   }
47
48   exec { 'bacula-fd restart-when-idle':
49     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
50     command     => 'sh -c "setsid /usr/local/sbin/bacula-idle-restart fd &"',
51     refreshonly => true,
52     subscribe   => [ File[$bacula_ssl_server_cert], File[$bacula_ssl_client_cert] ],
53     require     => File['/usr/local/sbin/bacula-idle-restart'],
54   }
55
56   file { '/etc/bacula/bacula-fd.conf':
57     ensure  => $ensure,
58     content => template('bacula/bacula-fd.conf.erb'),
59     mode    => '0640',
60     owner   => root,
61     group   => bacula,
62     require => Package['bacula-fd'],
63     notify  => Exec['bacula-fd restart-when-idle'],
64   }
65   file { '/usr/local/sbin/bacula-backup-dirs':
66     ensure  => $ensure,
67     mode    => '0775',
68     source  => 'puppet:///modules/bacula/bacula-backup-dirs',
69   }
70   file { '/usr/local/sbin/postbaculajob':
71     ensure  => $ensure,
72     mode    => '0775',
73     source  => 'puppet:///modules/bacula/postbaculajob',
74   }
75   file { '/etc/default/bacula-fd':
76     ensure  => $ensure,
77     content => template('bacula/default.bacula-fd.erb'),
78     mode    => '0400',
79     owner   => root,
80     group   => root,
81     require => Package['bacula-fd'],
82     notify  => Service['bacula-fd'],
83   }
84   if (versioncmp($::lsbmajdistrelease, '9') >= 0 and $systemd) {
85     dsa_systemd::override { 'bacula-fd':
86       content => @(EOT)
87         [Service]
88         ExecStart=
89         ExecStart=/usr/sbin/bacula-fd -c $CONFIG -f -u bacula -k
90         | EOT
91     }
92   } else {
93     dsa_systemd::override { 'bacula-fd':
94       ensure  => absent,
95     }
96   }
97
98   ferm::rule { 'dsa-bacula-fd':
99     domain      => '(ip ip6)',
100     description => 'Allow bacula access from storage and director',
101     rule        => "proto tcp mod state state (NEW) dport (${bacula_client_port}) saddr (${bacula_director_ip_addrs}) ACCEPT",
102   }
103 }