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 concat::fragment { "$pg_path/postgresql.conf listen":
65 target => "$pg_path/postgresql.conf",
66 content => "listen_addresses = ''\n",
70 concat::fragment { "$pg_path/postgresql.conf paths":
71 target => "$pg_path/postgresql.conf",
72 content => "unix_socket_directories = '$pg_path'\ndata_directory = '$pg_path'\nwal_level = logical\n",
75 $password_seed = lookup("base_installation::puppet_pass_seed")
76 $pg_host = $pg_backup_host
77 $pg_port = $pg_infos["dbport"]
78 $ldap_cn = lookup("base_installation::ldap_cn")
79 $ldap_password = generate_password(24, $password_seed, "ldap")
80 $pg_slot = regsubst($ldap_cn, '-', "_", "G")
83 $primary_conninfo = "host=$pg_host port=$pg_port user=$ldap_cn password=$ldap_password sslmode=require"
84 $primary_slot_name = $pg_slot
87 file { "$pg_path/recovery.conf":
91 content => template('postgresql/recovery.conf.erb'),
95 exec { "pg_basebackup $pg_path":
98 creates => "$pg_path/PG_VERSION",
99 environment => ["PGPASSWORD=$ldap_password"],
100 command => "/usr/bin/pg_basebackup -w -h $pg_host -p $pg_port -U $ldap_cn -D $pg_path -S $pg_slot",
102 Concat["$pg_path/pg_hba.conf"],
103 File["$pg_path/recovery.conf"],
104 Concat["$pg_path/postgresql.conf"],
109 ensure_resource("file", "/etc/systemd/system/postgresql_backup@.service", {
113 content => template("profile/postgresql/postgresql_backup@.service.erb"),
116 service { "postgresql_backup@$pg_backup_host":
120 File["/etc/systemd/system/postgresql_backup@.service"],
121 Concat["$pg_path/pg_hba.conf"],
122 File["$pg_path/recovery.conf"],
123 Concat["$pg_path/postgresql.conf"],
126 Concat["$pg_path/pg_hba.conf"],
127 File["$pg_path/recovery.conf"],
128 Concat["$pg_path/postgresql.conf"],
133 profile::postgresql::backup_dump { "$base_path/$pg_backup_host": }