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