Skip to content

Commit e5f1597

Browse files
(PE-40163) automate recovery of failed postgres server
1 parent 26c3ddf commit e5f1597

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

plans/replace_failed_postgresql.pp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# @summary Replaces a failed PostgreSQL host
2+
# @param primary_host - The hostname and certname of the primary Puppet server
3+
# @param replica_host - The hostname and certname of the replica VM
4+
# @param working_postgresql_host - The hostname and certname of the still-working PE-PostgreSQL server
5+
# @param failed_postgresql_host - The hostname and certname of the failed PE-PostgreSQL server
6+
# @param replacement_postgresql_host - The hostname and certname of the server being brought in to replace the failed PE-PostgreSQL server
7+
#
8+
plan peadm::replace_failed_postgresql(
9+
Peadm::SingleTargetSpec $primary_host,
10+
Peadm::SingleTargetSpec $replica_host,
11+
Peadm::SingleTargetSpec $working_postgresql_host,
12+
Peadm::SingleTargetSpec $failed_postgresql_host,
13+
Peadm::SingleTargetSpec $replacement_postgresql_host,
14+
) {
15+
$all_hosts = peadm::flatten_compact([
16+
$primary_host,
17+
$replica_host,
18+
$working_postgresql_host,
19+
$failed_postgresql_host,
20+
$replacement_postgresql_host,
21+
])
22+
23+
# verify we can connect to targets proded before proceeding
24+
run_command('hostname', $all_hosts)
25+
26+
# Get current peadm config before making modifications
27+
$peadm_config = run_task('peadm::get_peadm_config', $primary_host).first.value
28+
$compilers = $peadm_config['params']['compilers']
29+
30+
# Bail if this is trying to be ran against Standard
31+
if $compilers.empty {
32+
fail_plan('Plan peadm::add_database is only applicable for L and XL deployments')
33+
}
34+
35+
$pe_hosts = peadm::flatten_compact([
36+
$primary_host,
37+
$replica_host,
38+
])
39+
40+
# Stop puppet.service on Puppet server primary and replica
41+
run_task('service', $pe_hosts, 'action' => 'stop', 'name' => 'puppet.service')
42+
43+
# Temporarily set both primary and replica server nodes so that they use the remaining healthy PE-PostgreSQL server
44+
run_plan('peadm::util::update_db_setting', $pe_hosts,
45+
postgresql_host => $working_postgresql_host,
46+
override => true,
47+
)
48+
49+
# Restart pe-puppetdb.service on Puppet server primary and replica
50+
run_task('service', $pe_hosts, 'action' => 'restart', 'name' => 'pe-puppetdb.service')
51+
52+
# Purge failed PE-PostgreSQL node from PuppetDB
53+
run_command("/opt/puppetlabs/bin/puppet node purge ${$failed_postgresql_host}", $primary_host)
54+
55+
# Run peadm::add_database plan to deploy replacement PE-PostgreSQL server
56+
run_plan('peadm::add_database', targets => $replacement_postgresql_host,
57+
primary_host => $primary_host,
58+
)
59+
}

0 commit comments

Comments
 (0)