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