1 define profile::postgresql::backup_replication (
4 String $pg_user = "postgres",
5 String $pg_group = "postgres",
9 $host = find_host($facts["ldapvar"]["other"], $host_cn)
11 $pg_backup_host = $host_cn
12 } elsif has_key($host["vars"], "host") {
13 $pg_backup_host = $host["vars"]["host"][0]
15 $pg_backup_host = $host["vars"]["real_hostname"][0]
18 $pg_path = "$base_path/$pg_backup_host/postgresql"
21 ensure_resource("file", "$base_path/$pg_backup_host", {
30 require => File["$base_path/$pg_backup_host"],
34 profile::postgresql::base_pg_hba_rules { $pg_backup_host:
38 # postgresql.conf file and ssl
39 concat { "$pg_path/postgresql.conf":
46 if !empty($host) and has_key($host["vars"], "postgresql_backup_port") {
47 $pg_listen_port = $host["vars"]["postgresql_backup_port"][0]
49 profile::postgresql::ssl { $pg_path:
51 handle_concat_config => true,
52 before => Service["postgresql_backup@$pg_backup_host"]
55 concat::fragment { "$pg_path/postgresql.conf listen":
56 target => "$pg_path/postgresql.conf",
57 content => "listen_addresses = '*'\nport = $pg_listen_port\n",
60 profile::postgresql::replication { $host_cn:
61 target => "$pg_path/pg_hba.conf",
64 $pg_listen_port = undef
66 concat::fragment { "$pg_path/postgresql.conf listen":
67 target => "$pg_path/postgresql.conf",
68 content => "listen_addresses = ''\n",
72 concat::fragment { "$pg_path/postgresql.conf paths":
73 target => "$pg_path/postgresql.conf",
74 content => "unix_socket_directories = '$pg_path'\ndata_directory = '$pg_path'\nwal_level = logical\n",
77 $password_seed = lookup("base_installation::puppet_pass_seed")
78 $pg_host = $pg_backup_host
79 $pg_port = $pg_infos["dbport"]
80 $ldap_cn = lookup("base_installation::ldap_cn")
81 $ldap_password = generate_password(24, $password_seed, "ldap")
82 $pg_slot = regsubst($ldap_cn, '-', "_", "G")
85 $primary_conninfo = "host=$pg_host port=$pg_port user=$ldap_cn password=$ldap_password sslmode=require"
86 $primary_slot_name = $pg_slot
89 file { "$pg_path/recovery.conf":
93 content => template('postgresql/recovery.conf.erb'),
97 exec { "pg_basebackup $pg_path":
100 creates => "$pg_path/PG_VERSION",
101 environment => ["PGPASSWORD=$ldap_password"],
102 command => "/usr/bin/pg_basebackup -w -h $pg_host -p $pg_port -U $ldap_cn -D $pg_path -S $pg_slot",
104 Concat["$pg_path/pg_hba.conf"],
105 File["$pg_path/recovery.conf"],
106 Concat["$pg_path/postgresql.conf"],
111 ensure_resource("file", "/etc/systemd/system/postgresql_backup@.service", {
115 content => template("profile/postgresql/postgresql_backup@.service.erb"),
118 service { "postgresql_backup@$pg_backup_host":
122 File["/etc/systemd/system/postgresql_backup@.service"],
123 Concat["$pg_path/pg_hba.conf"],
124 File["$pg_path/recovery.conf"],
125 Concat["$pg_path/postgresql.conf"],
128 Concat["$pg_path/pg_hba.conf"],
129 File["$pg_path/recovery.conf"],
130 Concat["$pg_path/postgresql.conf"],
135 profile::postgresql::backup_dump { "$base_path/$pg_backup_host":
136 pg_port => $pg_listen_port,