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