5f7fba43c3b9f195dfffd9523f5896d73f59b5d1
[mirror/dsa-puppet.git] / modules / bacula / manifests / director.pp
1 # our bacula director
2 #
3 # @param pool_name      A token to be used in pool names
4 # @param db_address     hostname of the postgres server for the catalog DB
5 # @param db_port        port of the postgres server for the catalog DB
6 # @param db_name        DB name for the catalog DB
7 # @param db_user        username for the postgres server for the catalog DB
8 # @param db_password    password for the postgres server for the catalog DB
9 # @param port_dir       Port that the director should listen on
10 # @param db_sslca       SSL CA store for DB access
11 # @param director_name  bacula name of this dir instance
12 # @param director_address  address of this dir instance that other instances should connect to (dns name)
13 class bacula::director(
14   String  $db_address,
15   Integer $db_port,
16   String  $db_name = 'bacula',
17   String  $db_user = 'bacula',
18   String  $db_password = hkdf('/etc/puppet/secret', "bacula-db-${::hostname}"),
19   String  $pool_name = 'bacula',
20   Integer $port_dir = 9101,
21   Optional[String] $db_sslca = undef,
22   String $director_name = "${::fqdn}-dir",
23   Stdlib::Host $director_address = $::fqdn,
24 ) inherits bacula {
25
26   # used by e.g. bconsole
27   $director_secret = hkdf('/etc/puppet/secret', "bacula-dir-${::fqdn}")
28   # the RestoreFiles Job needs a Pool and a client.  Any valid pool and client.
29   $some_pool_name = "poolfull-${pool_name}-${director_address}"
30   $some_client_name = "${director_address}-fd"
31
32   # let the SD know we exist
33   @@bacula::storage::director{ $::fqdn:
34     tag              => 'bacula::to-storage',
35     director_name    => $director_name,
36     director_address => $director_address,
37   }
38   # let FDs know we exist
39   @@bacula::client::director{ $::fqdn:
40     tag              => "bacula::to-fd::${director_address}",
41     director_name    => $director_name,
42     director_address => $director_address,
43   }
44
45   ensure_packages ( [
46     'bacula-director-pgsql',
47     'bacula-common',
48     'bacula-common-pgsql'
49   ], {
50     ensure => 'installed',
51   })
52
53   service { 'bacula-director':
54     ensure    => running,
55     enable    => true,
56     hasstatus => true,
57     require   => Package['bacula-director-pgsql']
58   }
59   dsa_systemd::override { 'bacula-director':
60     content => @(EOT)
61       [Unit]
62       After=unbound.service
63       | EOT
64   }
65
66   exec { 'bacula-director reload':
67     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
68     command     => 'service bacula-director reload',
69     refreshonly => true,
70   }
71
72   file { '/etc/bacula/conf.d':
73     ensure  => directory,
74     mode    => '0755',
75     group   => bacula,
76     purge   => true,
77     force   => true,
78     recurse => true,
79     notify  => Exec['bacula-director reload']
80   }
81
82   file { '/etc/bacula/bacula-dir.conf':
83     content => template('bacula/bacula-dir.conf.erb'),
84     mode    => '0440',
85     group   => bacula,
86     require => Package['bacula-director-pgsql'],
87     notify  => Exec['bacula-director reload']
88   }
89
90   file { '/etc/bacula/conf.d/empty.conf':
91     content => '',
92     mode    => '0440',
93     group   => bacula,
94     require => Package['bacula-director-pgsql'],
95     notify  => Exec['bacula-director reload']
96   }
97
98   Bacula::Director::Client             <<| tag == "bacula::to-director::${::fqdn}" |>>
99   Bacula::Director::Client_from_storage<<| tag == "bacula::to-director::${::fqdn}" |>>
100
101   package { 'bacula-console':
102     ensure => installed;
103   }
104
105   file { '/etc/bacula/bconsole.conf':
106     content => template('bacula/bconsole.conf.erb'),
107     mode    => '0640',
108     group   => bacula,
109     require => Package['bacula-console']
110   }
111
112   package { 'python3-psycopg2': ensure => installed }
113   file { '/etc/bacula/scripts/volume-purge-action':
114     mode   => '0555',
115     source => 'puppet:///modules/bacula/volume-purge-action',
116     ;
117   }
118   file { '/etc/bacula/scripts/volumes-delete-old':
119     mode   => '0555',
120     source => 'puppet:///modules/bacula/volumes-delete-old',
121     ;
122   }
123   file { '/etc/bacula/storages-list.d':
124     ensure  => directory,
125     mode    => '0755',
126     group   => bacula,
127     purge   => true,
128     force   => true,
129     recurse => true,
130   }
131   file { '/usr/local/sbin/dsa-bacula-scheduler':
132     source => 'puppet:///modules/bacula/dsa-bacula-scheduler',
133     mode   => '0555',
134   }
135
136   file { '/etc/cron.d/puppet-bacula-stuff': ensure => absent, }
137   concat::fragment { 'puppet-crontab--bacula-director':
138     target  => '/etc/cron.d/puppet-crontab',
139     content => @("EOF"/$)
140       @daily root chronic /etc/bacula/scripts/volume-purge-action -v
141       @daily root chronic /etc/bacula/scripts/volumes-delete-old -v --token '${pool_name}'
142       */3 * * * * root sleep $(( \$RANDOM \\% 60 )); flock -w 0 -e /usr/local/sbin/dsa-bacula-scheduler /usr/local/sbin/dsa-bacula-scheduler
143       | EOF
144   }
145
146   concat { $bacula::bacula_dsa_client_list:
147   }
148   concat::fragment { 'bacula-dsa-client-list::header' :
149     target  => $bacula::bacula_dsa_client_list,
150     content => '',
151     order   => '00',
152   }
153   Concat::Fragment <<| tag == $bacula::tag_bacula_dsa_client_list |>>
154
155   @@ferm::rule::simple { "bacula::director-to-fd::${::fqdn}":
156     tag         => "bacula::director-to-fd::${::fqdn}",
157     description => 'Allow bacula-fd from the bacula-director',
158     port        => '7', # overridden on collecting
159     saddr       => $bacula::public_addresses,
160   }
161   @@ferm::rule::simple { "bacula::director-to-storage::${::fqdn}":
162     tag         => 'bacula::director-to-storage',
163     description => 'Allow bacula-storage access from the bacula-director',
164     chain       => 'bacula-sd',
165     saddr       => $bacula::public_addresses,
166   }
167 }