Puppet Class: postgresql::server

Defined in:
modules/postgresql/manifests/server.pp

Overview

Class: postgresql::server

This class installs postgresql packages, standard configuration

Parameters:

pgversion
    Defaults to 9.3 in Ubuntu Trusty and 9.4 in Debian jessie.
    FIXME: Just use the unversioned package name and let apt
    do the right thing.
ensure
    Defaults to present
includes
    An array of files that will be included in the config. It is
    the caller's responsibility to provide these
root_dir
    The root directory for postgresql data. The actual directory will be
    "${root_dir}/${pgversion}/main".
use_ssl
    Enable ssl

Actions:

Install/configure postgresql

Requires:

Sample Usage:

include postgresql::server

Parameters:

  • pgversion (Any) (defaults to: $::lsbdistcodename)
  • ensure (Any) (defaults to: 'present')
  • includes (Any) (defaults to: [])
  • listen_addresses (Any) (defaults to: '*')
  • port (Any) (defaults to: '5432')
  • root_dir (Any) (defaults to: '/var/lib/postgresql')
  • use_ssl (Any) (defaults to: false)
  • ssldir (Any) (defaults to: undef)


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
# File 'modules/postgresql/manifests/server.pp', line 29

class postgresql::server(
    $pgversion        = $::lsbdistcodename ? {
        'stretch' => '9.6',
        'jessie'  => '9.4',
    },
    $ensure           = 'present',
    $includes         = [],
    $listen_addresses = '*',
    $port             = '5432',
    $root_dir         = '/var/lib/postgresql',
    $use_ssl          = false,
    $ssldir           = undef,
) {

    package { [
        "postgresql-${pgversion}",
        "postgresql-${pgversion}-debversion",
        "postgresql-client-${pgversion}",
        "postgresql-contrib-${pgversion}",
        'libdbi-perl',
        'libdbd-pg-perl',
        'ptop',
        'check-postgres',
    ]:
        ensure => $ensure,
    }

    class { '::postgresql::dirs':
        ensure    => $ensure,
        pgversion => $pgversion,
        root_dir  => $root_dir,
    }

    $data_dir = "${root_dir}/${pgversion}/main"

    $service_name = $::lsbdistcodename ? {
        'jessie' => "postgresql@${pgversion}-main",
        default  => 'postgresql',
    }
    exec { 'pgreload':
        command     => "/usr/bin/pg_ctlcluster ${pgversion} main reload",
        user        => 'postgres',
        refreshonly => true,
    }

    if $use_ssl {
        file { "/etc/postgresql/${pgversion}/main/ssl.conf":
            ensure  => $ensure,
            source  => 'puppet:///modules/postgresql/ssl.conf',
            owner   => 'root',
            group   => 'root',
            mode    => '0444',
            require => Base::Expose_puppet_certs['/etc/postgresql'],
            before  => Service[$service_name],
        }

        ::base::expose_puppet_certs { '/etc/postgresql':
            ensure          => $ensure,
            provide_private => true,
            user            => 'postgres',
            group           => 'postgres',
            ssldir          => $ssldir,
        }
    }

    service { $service_name:
        ensure  => ensure_service($ensure),
    }

    file { "/etc/postgresql/${pgversion}/main/postgresql.conf":
        ensure  => $ensure,
        content => template('postgresql/postgresql.conf.erb'),
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
    }
}