Puppet Class: bacula::director

Defined in:
manifests/director.pp

Overview

Class: bacula::director

This class manages the Bacula director component

Parameters

All bacula classes are called from the main ::bacula class. Parameters are documented there.

Copyright 2012 Russell Harrison

License

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Parameters:

  • backup_catalog (Any) (defaults to: true)
  • clients (Any) (defaults to: undef)
  • console_password (Any) (defaults to: '')
  • db_backend (Any) (defaults to: 'sqlite')
  • db_database (Any) (defaults to: 'bacula')
  • db_host (Any) (defaults to: 'localhost')
  • db_password (Any) (defaults to: '')
  • db_port (Any) (defaults to: '3306')
  • db_user (Any) (defaults to: '')
  • db_user_host (Any) (defaults to: undef)
  • dir_template (Any) (defaults to: 'bacula/bacula-dir.conf.erb')
  • director_password (Any) (defaults to: '')
  • director_server (Any) (defaults to: undef)
  • mail_to (Any) (defaults to: undef)
  • mail_to_daemon (Any) (defaults to: undef)
  • mail_to_on_error (Any) (defaults to: undef)
  • mail_to_operator (Any) (defaults to: undef)
  • manage_config_dir (Any) (defaults to: false)
  • manage_db (Any) (defaults to: false)
  • manage_db_tables (Any) (defaults to: true)
  • manage_logwatch (Any) (defaults to: undef)
  • plugin_dir (Any) (defaults to: undef)
  • storage_server (Any) (defaults to: undef)
  • tls_allowed_cn (Any) (defaults to: [])
  • tls_ca_cert (Any) (defaults to: undef)
  • tls_ca_cert_dir (Any) (defaults to: undef)
  • tls_cert (Any) (defaults to: undef)
  • tls_key (Any) (defaults to: undef)
  • tls_require (Any) (defaults to: 'yes')
  • tls_verify_peer (Any) (defaults to: 'yes')
  • use_console (Any) (defaults to: false)
  • use_tls (Any) (defaults to: false)
  • volume_retention (Any) (defaults to: '1 Year')
  • volume_retention_diff (Any) (defaults to: '40 Days')
  • volume_retention_full (Any) (defaults to: '1 Year')
  • volume_retention_incr (Any) (defaults to: '10 Days')


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'manifests/director.pp', line 28

class bacula::director (
  $backup_catalog        = true,
  $clients               = undef,
  $console_password      = '',
  $db_backend            = 'sqlite',
  $db_database           = 'bacula',
  $db_host               = 'localhost',
  $db_password           = '',
  $db_port               = '3306',
  $db_user               = '',
  $db_user_host          = undef,
  $dir_template          = 'bacula/bacula-dir.conf.erb',
  $director_password     = '',
  $director_server       = undef,
  $mail_to               = undef,
  $mail_to_daemon        = undef,
  $mail_to_on_error      = undef,
  $mail_to_operator      = undef,
  $manage_config_dir     = false,
  $manage_db             = false,
  $manage_db_tables      = true,
  $manage_logwatch       = undef,
  $plugin_dir            = undef,
  $storage_server        = undef,
  $tls_allowed_cn        = [],
  $tls_ca_cert           = undef,
  $tls_ca_cert_dir       = undef,
  $tls_cert              = undef,
  $tls_key               = undef,
  $tls_require           = 'yes',
  $tls_verify_peer       = 'yes',
  $use_console           = false,
  $use_tls               = false,
  $volume_retention      = '1 Year',
  $volume_retention_diff = '40 Days',
  $volume_retention_full = '1 Year',
  $volume_retention_incr = '10 Days'
) {
  include ::bacula::params

  $director_server_real = $director_server ? {
    undef   => $::bacula::params::director_server_default,
    default => $director_server,
  }

  # Allow <code>$mail_to_real</cdoe> to be <code>undef</code> only if <code>$mail_to_on_error</code> is supplied and set a default
  # if it isn't.
  if $mail_to_on_error {
    $mail_to_real = $mail_to
  } else {
    $mail_to_real = $mail_to ? {
      undef   => $::bacula::params::mail_to_default,
      default => $mail_to,
    }
  }

  # If <code>$mail_to_daemon</code> and / or <code>$mail_to_operator</code> is undefined set <code>_real</code> variables to be
  # either <code>$mail_to_real</code> or <code>$mail_to_on_error</code> in that order.
  if $mail_to_real {
    $mail_to_daemon_real   = $mail_to_daemon ? {
      undef   => $mail_to_real,
      default => $mail_to_daemon,
    }
    $mail_to_operator_real = $mail_to_operator ? {
      undef   => $mail_to_real,
      default => $mail_to_operator,
    }
  } elsif $mail_to_on_error {
    $mail_to_daemon_real   = $mail_to_daemon ? {
      undef   => $mail_to_on_error,
      default => $mail_to_daemon,
    }
    $mail_to_operator_real = $mail_to_operator ? {
      undef   => $mail_to_on_error,
      default => $mail_to_operator,
    }
  }

  $storage_server_real = $storage_server ? {
    undef   => $::bacula::params::storage_server_default,
    default => $storage_server,
  }

  if $clients != undef {
    # This function takes each client specified in <tt>$clients</tt>
    # and generates a <tt>bacula::client</tt> resource for each
    create_resources('bacula::client::config', $clients)
  }
  # TODO add postgresql support
  $db_package = $db_backend ? {
    'mysql'      => $::bacula::params::director_mysql_package,
    'postgresql' => $::bacula::params::director_postgresql_package,
    default      => $::bacula::params::director_sqlite_package,
  }

  package { $db_package:
    ensure => present,
  }

  $config_dir_source = $manage_config_dir ? {
    true    => 'puppet:///modules/bacula/bacula-empty.dir',
    default => undef,
  }

  # Create the configuration for the Director and make sure the directory for
  # the per-Client configuration is created before we run the realization for
  # the exported files below
  file { '/etc/bacula/bacula-dir.d':
    ensure  => directory,
    owner   => 'bacula',
    group   => 'bacula',
    mode    => '0750',
    purge   => $manage_config_dir,
    force   => $manage_config_dir,
    recurse => $manage_config_dir,
    source  => $config_dir_source,
    require => Package[$db_package],
  }

  file { '/etc/bacula/bacula-dir.d/empty.conf':
    ensure  => file,
    owner   => 'bacula',
    group   => 'bacula',
    mode    => '0640',
    content => '',
  }

  $file_requires = $plugin_dir ? {
    undef   => File[
      '/etc/bacula/bacula-dir.d',
      '/etc/bacula/bacula-dir.d/empty.conf',
      '/var/lib/bacula',
      '/var/log/bacula',
      '/var/spool/bacula',
      '/var/run/bacula'
    ],
    default => File[
      '/etc/bacula/bacula-dir.d',
      '/etc/bacula/bacula-dir.d/empty.conf',
      '/var/lib/bacula',
      '/var/log/bacula',
      '/var/spool/bacula',
      '/var/run/bacula',
      $plugin_dir
    ],
  }

  file { '/etc/bacula/bacula-dir.conf':
    ensure  => file,
    owner   => 'bacula',
    group   => 'bacula',
    mode    => '0640',
    content => template($dir_template),
    require => $file_requires,
    notify  => Service['bacula-dir'],
  }

  if $backup_catalog {
    File["/etc/bacula/bacula-dir.d/${director_server_real}.conf"] -> File['/etc/bacula/bacula-dir.conf']
  }

  if $manage_db_tables {
    case $db_backend {
      'mysql'  : {
        class { '::bacula::director::mysql':
          db_database  => $db_database,
          db_user      => $db_user,
          db_password  => $db_password,
          db_port      => $db_port,
          db_host      => $db_host,
          db_user_host => $db_user_host,
          manage_db    => $manage_db,
        }
      }
      'sqlite' : {
        class { '::bacula::director::sqlite':
          db_database => $db_database,
        }
      }
      default  : {
        fail "The bacula module does not support managing the ${db_backend} backend database"
      }
    }
  }

  # Register the Service so we can manage it through Puppet
  if $manage_db_tables {
    $service_require = Exec['make_db_tables']
  } else {
    $service_require = undef
  }

  service { 'bacula-dir':
    ensure     => running,
    name       => $::bacula::params::director_service,
    enable     => true,
    hasstatus  => true,
    hasrestart => true,
    require    => $service_require,
  }
}