Puppet Class: roundcube::database::postgresql

Inherits:
roundcube::params
Defined in:
manifests/database/postgresql.pp

Overview

Class for creating the RoundCube postgresql database.

Parameters:

  • listen_addresses (Any) (defaults to: $roundcube::params::database_host)
  • database_host (Any) (defaults to: $roundcube::params::database_host)
  • database_name (Any) (defaults to: $roundcube::params::database_name)
  • database_username (Any) (defaults to: $roundcube::params::database_username)
  • database_password (Any) (defaults to: $roundcube::params::database_password)
  • ip_mask_allow_all_users (Any) (defaults to: $roundcube::params::ip_mask_allow_all_users)


2
3
4
5
6
7
8
9
10
11
12
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
# File 'manifests/database/postgresql.pp', line 2

class roundcube::database::postgresql (
  $listen_addresses        = $roundcube::params::database_host,
  $database_host           = $roundcube::params::database_host,
  $database_name           = $roundcube::params::database_name,
  $database_username       = $roundcube::params::database_username,
  $database_password       = $roundcube::params::database_password,
  $ip_mask_allow_all_users = $roundcube::params::ip_mask_allow_all_users,
) inherits roundcube::params {

  # get the pg server up and running
  class { '::postgresql::server':
    ip_mask_allow_all_users => $ip_mask_allow_all_users,
    listen_addresses        => $listen_addresses,
  }

  # create the roundcube database
  postgresql::server::db { $database_name:
    user     => $database_username,
    password => $database_password,
  }

  #Create role for database user
  postgresql::server::role { $database_username:
    password_hash => postgresql_password($database_username, $database_password),
  }

  #TODO: This part of the class is scaffold work required to get the schema for the roundcube database
  #      loaded and is pretty gross.  The postgres.initial.sql file was taken from the roundcube github site.
  #      The schema needs to be imported as the user that the database is created with because of the
  #      lacking functionality of the postgresql::server::grant class. So we should probably refactor
  #      once that class is ported to ruby.

  file { '/tmp/postgres.initial.sql':
    ensure => present,
    source => 'puppet:///modules/roundcube/postgres.initial.sql',
  }

  concat { '/var/lib/postgresql/.pgpass':
    ensure  => present,
    mode    => '0600',
    owner   => 'postgres',
    group   => 'postgres',
    require => Postgresql::Server::Db[$database_name],
  }

  concat::fragment { 'pgpass_initial':
    target  => '/var/lib/postgresql/.pgpass',
    content => "${database_host}:*:${database_name}:${database_username}:${database_password}\n",
  }

  # create the table structure
  exec { 'create_schema':
    command => "sudo -u postgres -i psql -U ${database_username} -h ${database_host} ${database_name} < /tmp/postgres.initial.sql",
    onlyif  => "sudo -u postgres -i psql ${database_name} -c \"\\dt\" | grep -c \"No relations found.\"",
    require => [ Postgresql::Server::Db[$database_name], File['/tmp/postgres.initial.sql'], Concat['/var/lib/postgresql/.pgpass'] ],
  }

}