Skip to content

Commit f5a2417

Browse files
(PE-40163) automate recovery of failed postgres server (#537)
* (PE-40163) automate recovery of failed postgres server * (PE-40163) alternate approach to running a task * (PE-40163) deal with empty csr attributes * (PE-40163) update reference.md
1 parent 2aaacfc commit f5a2417

File tree

3 files changed

+108
-3
lines changed

3 files changed

+108
-3
lines changed

REFERENCE.md

+45
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Supported use cases:
109109
* [`peadm::convert`](#peadm--convert): Convert an existing PE cluster to a PEAdm-managed cluster
110110
* [`peadm::install`](#peadm--install): Install a new PE cluster
111111
* [`peadm::modify_certificate`](#peadm--modify_certificate): Modify the certificate of one or more targets
112+
* [`peadm::replace_failed_postgresql`](#peadm--replace_failed_postgresql): Replaces a failed PostgreSQL host
112113
* [`peadm::restore`](#peadm--restore): Restore puppet primary configuration
113114
* [`peadm::restore_ca`](#peadm--restore_ca)
114115
* [`peadm::status`](#peadm--status): Return status information from one or more PE clusters in a table format
@@ -2370,6 +2371,50 @@ Data type: `Boolean`
23702371

23712372
Default value: `false`
23722373

2374+
### <a name="peadm--replace_failed_postgresql"></a>`peadm::replace_failed_postgresql`
2375+
2376+
Replaces a failed PostgreSQL host
2377+
2378+
#### Parameters
2379+
2380+
The following parameters are available in the `peadm::replace_failed_postgresql` plan:
2381+
2382+
* [`primary_host`](#-peadm--replace_failed_postgresql--primary_host)
2383+
* [`replica_host`](#-peadm--replace_failed_postgresql--replica_host)
2384+
* [`working_postgresql_host`](#-peadm--replace_failed_postgresql--working_postgresql_host)
2385+
* [`failed_postgresql_host`](#-peadm--replace_failed_postgresql--failed_postgresql_host)
2386+
* [`replacement_postgresql_host`](#-peadm--replace_failed_postgresql--replacement_postgresql_host)
2387+
2388+
##### <a name="-peadm--replace_failed_postgresql--primary_host"></a>`primary_host`
2389+
2390+
Data type: `Peadm::SingleTargetSpec`
2391+
2392+
- The hostname and certname of the primary Puppet server
2393+
2394+
##### <a name="-peadm--replace_failed_postgresql--replica_host"></a>`replica_host`
2395+
2396+
Data type: `Peadm::SingleTargetSpec`
2397+
2398+
- The hostname and certname of the replica VM
2399+
2400+
##### <a name="-peadm--replace_failed_postgresql--working_postgresql_host"></a>`working_postgresql_host`
2401+
2402+
Data type: `Peadm::SingleTargetSpec`
2403+
2404+
- The hostname and certname of the still-working PE-PostgreSQL server
2405+
2406+
##### <a name="-peadm--replace_failed_postgresql--failed_postgresql_host"></a>`failed_postgresql_host`
2407+
2408+
Data type: `Peadm::SingleTargetSpec`
2409+
2410+
- The hostname and certname of the failed PE-PostgreSQL server
2411+
2412+
##### <a name="-peadm--replace_failed_postgresql--replacement_postgresql_host"></a>`replacement_postgresql_host`
2413+
2414+
Data type: `Peadm::SingleTargetSpec`
2415+
2416+
- The hostname and certname of the server being brought in to replace the failed PE-PostgreSQL server
2417+
23732418
### <a name="peadm--restore"></a>`peadm::restore`
23742419

23752420
Restore puppet primary configuration

plans/replace_failed_postgresql.pp

+59
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::replace_failed_postgresql 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+
}

plans/util/insert_csr_extension_requests.pp

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
# If we're merging extension requests, existing requests will be preserved.
1616
# If we're not merging, only ours will be used; existing requests will be
1717
# overwritten.
18-
$csr_file_data = $merge ? {
19-
true => $csr_attributes_data.deep_merge({ 'extension_requests' => $extension_requests }),
20-
false => ($csr_attributes_data + { 'extension_requests' => $extension_requests }),
18+
if $merge and !$csr_attributes_data.empty {
19+
$csr_file_data = $csr_attributes_data.deep_merge({ 'extension_requests' => $extension_requests })
20+
} else {
21+
$csr_file_data = $csr_attributes_data + { 'extension_requests' => $extension_requests }
2122
}
2223

2324
run_task('peadm::mkdir_p_file', $target,

0 commit comments

Comments
 (0)