Puppet Class: bacula::common

Defined in:
manifests/common.pp

Overview

Class: bacula::common

This class enforces common resources needed by all bacula components

Actions:

- Enforce the bacula user and groups exist
- Enforce the /var/spool/bacula is a director and /var/lib/bacula points to it

Sample Usage:

class { ‘bacula::common’: }

Parameters:

  • packages (Any) (defaults to: '')
  • manage_db_tables (Any)
  • db_backend (Any)
  • db_user (Any)
  • db_database (Any)
  • db_password (Any)
  • db_port (Any)
  • db_host (Any)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
# File 'manifests/common.pp', line 13

class bacula::common(
    $packages = '',
    $manage_db_tables,
    $db_backend,
    $db_user,
    $db_database,
    $db_password,
    $db_port,
    $db_host
  ) {

  if $packages {
    package { $packages: 
      ensure => installed,
      notify => $manage_db_tables ? {
        true  => Exec['make_db_tables'],
        false => undef,
      }
    }
  }

  $db_parameters = $db_backend ? {
    'sqlite' => '',
    'mysql'  => "--host=${db_host} --user=${db_user} --password=${db_password} --port=${db_port} --database=${db_database}",
  }

  if $manage_db_tables {
    exec { 'make_db_tables':
      command     => "/usr/lib/bacula/make_bacula_tables ${db_parameters}",
      refreshonly => true,
    }
  }

  if $manage_db {
    case $db_backend {
      'mysql': {
        mysql::db { $db_database:
          user     => $db_user,
          password => $db_password,
          host     => $db_host,
          notify   => $manage_db_tables ? {
            true  => Exec['make_db_tables'],
            false => undef,
          },
          require => defined(Class['mysql::server']) ? {
            true  => Class['mysql::server'],
            false => undef,
          },
        }
      }

      'sqlite': {
        sqlite::db { $db_database:
          location => "/var/lib/bacula/${db_database}.db", 
          owner    => 'bacula',
          group    => 'bacula',
          ensure   => present,
          require  => File['/var/lib/bacula'],
        }
      }

      default: {
        fail "The bacula module does not support managing the ${db_backend} backend database"
      }
    }
  }

  user { 'bacula':
    ensure => present,
    gid    => 'bacula',
  }

  group { 'bacula':
    ensure => present,
  }

  file { '/var/lib/bacula':
    ensure => directory,
    owner  => bacula,
    group  => bacula,
  }

  file { '/var/spool/bacula':
    ensure => directory,
    owner  => bacula,
    group  => bacula,
  }

  file { '/var/log/bacula':
    ensure  => directory,
    owner   => bacula,
    group   => bacula,
    recurse => true,
  }

  file { '/var/run/bacula':
    ensure => directory,
    owner  => bacula,
    group  => bacula,
  }
}