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