Puppet Class: profile::toolforge::harbor::db

Defined in:
modules/profile/manifests/toolforge/harbor/db.pp

Overview

Parameters:

  • harbor_pwd (String) (defaults to: lookup('profile::toolforge::harbor::db::harbor_pwd'))
  • db_replica (Optional[Stdlib::Host]) (defaults to: lookup('profile::toolforge::harbor::db::replica', {default_value => undef}))
  • replication_pass (Optional[String]) (defaults to: lookup('profile::toolforge::harbor::db::replication_pass', {default_value => undef}))
  • db_primary (Stdlib::Host) (defaults to: lookup('profile::toolforge::harbor::db::primary'))
  • root_dir (Stdlib::Unixpath) (defaults to: lookup('profile::toolforge::harbor::db::root_dir', {default_value => '/srv/postgres'}))


1
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
60
# File 'modules/profile/manifests/toolforge/harbor/db.pp', line 1

class profile::toolforge::harbor::db (
    String $harbor_pwd = lookup('profile::toolforge::harbor::db::harbor_pwd'),
    Optional[Stdlib::Host] $db_replica = lookup('profile::toolforge::harbor::db::replica', {default_value => undef}),
    Optional[String] $replication_pass = lookup('profile::toolforge::harbor::db::replication_pass', {default_value => undef}),
    Stdlib::Host $db_primary = lookup('profile::toolforge::harbor::db::primary'),
    Stdlib::Unixpath $root_dir = lookup('profile::toolforge::harbor::db::root_dir', {default_value => '/srv/postgres'}),
){
    require profile::wmcs::services::postgres::common
    require profile::prometheus::postgres_exporter

    if $db_primary == $facts['networking']['fqdn'] {
        # db_role is only used for the motd in role::wmcs::toolforce::harbor::db
        $db_role = 'primary'
        $on_primary = true
    } else {
        $db_role = 'replica'
        $on_primary = false
    }

    if $on_primary {
        class { 'postgresql::master':
            root_dir => $root_dir,
        }
        if $db_replica {
            $db_replica_v4 = ipresolve($db_replica, 4)
            if $db_replica_v4 {
                postgresql::user { "replication@${db_replica}-v4":
                    ensure   => 'present',
                    user     => 'replication',
                    password => $replication_pass,
                    cidr     => "${db_replica_v4}/32",
                    type     => 'host',
                    method   => 'md5',
                    attrs    => 'REPLICATION',
                    database => 'all',
                }
            }
        }
        postgresql::user { 'harbor@eqiad1r':
            ensure   => 'present',
            user     => 'harbor',
            password => $harbor_pwd,
            cidr     => '172.16.0.0/21',
            type     => 'host',
            method   => 'trust',
            database => 'harbor',
        }
        postgresql::db { 'harbor':
            owner => 'harbor'
        }
    } elsif $replication_pass and $db_replica {
        class {'postgresql::slave':
            master_server    => $db_primary,
            replication_pass => $replication_pass,
            root_dir         => $root_dir,
        }
    } else {
        fail('If this is not the primary, this must have replication settings.')
    }
}