diff --git a/REFERENCE.md b/REFERENCE.md
index c0376477..b7827e8c 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -2322,6 +2322,8 @@ The following parameters are available in the `peadm::migrate` plan:
* [`old_primary_host`](#-peadm--migrate--old_primary_host)
* [`new_primary_host`](#-peadm--migrate--new_primary_host)
+* [`upgrade_version`](#-peadm--migrate--upgrade_version)
+* [`replica_host`](#-peadm--migrate--replica_host)
##### `old_primary_host`
@@ -2335,6 +2337,22 @@ Data type: `Peadm::SingleTargetSpec`
The new server that will become the PE primary server
+##### `upgrade_version`
+
+Data type: `Optional[String]`
+
+Optional version to upgrade to after migration is complete
+
+Default value: `undef`
+
+##### `replica_host`
+
+Data type: `Optional[Peadm::SingleTargetSpec]`
+
+
+
+Default value: `undef`
+
### `peadm::modify_certificate`
Certificates can be modified by adding extensions, removing extensions, or
diff --git a/plans/migrate.pp b/plans/migrate.pp
index c9aa7197..fdb690b4 100644
--- a/plans/migrate.pp
+++ b/plans/migrate.pp
@@ -4,10 +4,14 @@
# The existing PE primary server that will be migrated from
# @param new_primary_host
# The new server that will become the PE primary server
+# @param upgrade_version
+# Optional version to upgrade to after migration is complete
#
plan peadm::migrate (
Peadm::SingleTargetSpec $old_primary_host,
Peadm::SingleTargetSpec $new_primary_host,
+ Optional[String] $upgrade_version = undef,
+ Optional[Peadm::SingleTargetSpec] $replica_host = undef,
) {
peadm::assert_supported_bolt_version()
@@ -15,18 +19,20 @@
backup_type => 'migration',
})
- download_file($backup_file['path'], 'backup', $old_primary_host)
+ $download_results = download_file($backup_file['path'], 'backup', $old_primary_host)
+ $download_path = $download_results[0]['path']
$backup_filename = basename($backup_file['path'])
$remote_backup_path = "/tmp/${backup_filename}"
- $current_dir = system::env('PWD')
- upload_file("${current_dir}/downloads/backup/${old_primary_host}/${backup_filename}", $remote_backup_path, $new_primary_host)
+ upload_file($download_path, $remote_backup_path, $new_primary_host)
$old_primary_target = get_targets($old_primary_host)[0]
$old_primary_password = peadm::get_pe_conf($old_primary_target)['console_admin_password']
$old_pe_conf = run_task('peadm::get_peadm_config', $old_primary_target).first.value
+ out::message("old_pe_conf:${old_pe_conf}.")
+
run_plan('peadm::install', {
primary_host => $new_primary_host,
console_password => $old_primary_password,
@@ -40,4 +46,55 @@
restore_type => 'migration',
input_file => $remote_backup_path,
})
+
+ $node_types = {
+ 'primary_host' => $old_pe_conf['params']['primary_host'],
+ 'replica_host' => $old_pe_conf['params']['replica_host'],
+ 'primary_postgresql_host' => $old_pe_conf['params']['primary_postgresql_host'],
+ 'replica_postgresql_host' => $old_pe_conf['params']['replica_postgresql_host'],
+ 'compilers' => $old_pe_conf['params']['compilers'],
+ 'legacy_compilers' => $old_pe_conf['params']['legacy_compilers'],
+ }
+
+ $nodes_to_purge = $node_types.reduce([]) |$memo, $entry| {
+ $value = $entry[1]
+
+ if empty($value) {
+ $memo
+ }
+ elsif $value =~ Array {
+ $memo + $value.filter |$node| { !empty($node) }
+ }
+ else {
+ $memo + [$value]
+ }
+ }
+
+ out::message("Nodes to purge: ${nodes_to_purge}")
+
+ if !empty($nodes_to_purge) {
+ out::message('Purging nodes from old configuration individually')
+ $nodes_to_purge.each |$node| {
+ out::message("Purging node: ${node}")
+ run_command("/opt/puppetlabs/bin/puppet node purge ${node}", $new_primary_host)
+ }
+ } else {
+ out::message('No nodes to purge from old configuration')
+ }
+
+ if $replica_host {
+ run_plan('peadm::add_replica', {
+ primary_host => $new_primary_host,
+ replica_host => $replica_host,
+ })
+ }
+
+ if $upgrade_version and $upgrade_version != '' and !empty($upgrade_version) {
+ run_plan('peadm::upgrade', {
+ primary_host => $new_primary_host,
+ version => $upgrade_version,
+ download_mode => 'direct',
+ replica_host => $replica_host,
+ })
+ }
}