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