Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PE-40163) automate recovery of failed postgres server #537

Merged
merged 4 commits into from
Feb 12, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions plans/replace_failed_postgresql.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# @summary Replaces a failed PostgreSQL host
# @param primary_host - The hostname and certname of the primary Puppet server
# @param replica_host - The hostname and certname of the replica VM
# @param working_postgresql_host - The hostname and certname of the still-working PE-PostgreSQL server
# @param failed_postgresql_host - The hostname and certname of the failed PE-PostgreSQL server
# @param replacement_postgresql_host - The hostname and certname of the server being brought in to replace the failed PE-PostgreSQL server
#
plan peadm::replace_failed_postgresql(
Peadm::SingleTargetSpec $primary_host,
Peadm::SingleTargetSpec $replica_host,
Peadm::SingleTargetSpec $working_postgresql_host,
Peadm::SingleTargetSpec $failed_postgresql_host,
Peadm::SingleTargetSpec $replacement_postgresql_host,
) {
$all_hosts = peadm::flatten_compact([
$primary_host,
$replica_host,
$working_postgresql_host,
$failed_postgresql_host,
$replacement_postgresql_host,
])

# verify we can connect to targets proded before proceeding
run_command('hostname', $all_hosts)

# Get current peadm config before making modifications
$peadm_config = run_task('peadm::get_peadm_config', $primary_host).first.value
$compilers = $peadm_config['params']['compilers']

# Bail if this is trying to be ran against Standard
if $compilers.empty {
fail_plan('Plan peadm::add_database is only applicable for L and XL deployments')
}

$pe_hosts = peadm::flatten_compact([
$primary_host,
$replica_host,
])

# Stop puppet.service on Puppet server primary and replica
run_task('service', $pe_hosts, 'action' => 'stop', 'name' => 'puppet.service')

# Temporarily set both primary and replica server nodes so that they use the remaining healthy PE-PostgreSQL server
run_plan('peadm::util::update_db_setting', $pe_hosts,
postgresql_host => $working_postgresql_host,
override => true,
)

# Restart pe-puppetdb.service on Puppet server primary and replica
run_task('service', $pe_hosts, 'action' => 'restart', 'name' => 'pe-puppetdb.service')

# Purge failed PE-PostgreSQL node from PuppetDB
run_command("/opt/puppetlabs/bin/puppet node purge ${$failed_postgresql_host}", $primary_host)

# Run peadm::add_database plan to deploy replacement PE-PostgreSQL server
run_plan('peadm::add_database', targets => $replacement_postgresql_host,
Copy link
Contributor Author

@davidmalloncares davidmalloncares Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ragingra there seems to be an issue with this line. If I run this plan with this line commented out and then run that line manually it all works ok. Do you see anything obvious in how I am calling it here vs how it is called manually?

bolt plan run peadm::add_database -t <replacement-postgres-server-fqdn> primary_host=<primary-server-fqdn>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ragingra I got a fix for the issue I was having and finally got all the tests to go green - could you take a wee look? :)

primary_host => $primary_host,
)
}
Loading