|
| 1 | +# @summary Migrate a PE primary server to a new host |
| 2 | +# |
| 3 | +# @param old_primary_host |
| 4 | +# The existing PE primary server that will be migrated from |
| 5 | +# @param new_primary_host |
| 6 | +# The new server that will become the PE primary server |
| 7 | +# @param upgrade_version |
| 8 | +# Optional version to upgrade to after migration is complete |
| 9 | +# |
| 10 | +plan peadm::migrate ( |
| 11 | + Peadm::SingleTargetSpec $old_primary_host, |
| 12 | + Peadm::SingleTargetSpec $new_primary_host, |
| 13 | + Optional[String] $upgrade_version = undef, |
| 14 | + Optional[Peadm::SingleTargetSpec] $replica_host = undef, |
| 15 | +) { |
| 16 | + peadm::assert_supported_bolt_version() |
| 17 | + |
| 18 | + $backup_file = run_plan('peadm::backup', $old_primary_host, { |
| 19 | + backup_type => 'migration', |
| 20 | + }) |
| 21 | + |
| 22 | + $download_results = download_file($backup_file['path'], 'backup', $old_primary_host) |
| 23 | + $download_path = $download_results[0]['path'] |
| 24 | + |
| 25 | + $backup_filename = basename($backup_file['path']) |
| 26 | + $remote_backup_path = "/tmp/${backup_filename}" |
| 27 | + |
| 28 | + upload_file($download_path, $remote_backup_path, $new_primary_host) |
| 29 | + |
| 30 | + $old_primary_target = get_targets($old_primary_host)[0] |
| 31 | + $old_primary_password = peadm::get_pe_conf($old_primary_target)['console_admin_password'] |
| 32 | + $old_pe_conf = run_task('peadm::get_peadm_config', $old_primary_target).first.value |
| 33 | + |
| 34 | + out::message("old_pe_conf:${old_pe_conf}.") |
| 35 | + |
| 36 | + # run_plan('peadm::install', { |
| 37 | + # primary_host => $new_primary_host, |
| 38 | + # console_password => $old_primary_password, |
| 39 | + # code_manager_auto_configure => true, |
| 40 | + # download_mode => 'direct', |
| 41 | + # version => $old_pe_conf['pe_version'], |
| 42 | + # }) |
| 43 | + |
| 44 | + # run_plan('peadm::restore', { |
| 45 | + # targets => $new_primary_host, |
| 46 | + # restore_type => 'migration', |
| 47 | + # input_file => $remote_backup_path, |
| 48 | + # }) |
| 49 | + |
| 50 | + # Use the old PE configuration to determine which nodes to purge |
| 51 | + $old_primary_host_value = $old_pe_conf['params']['primary_host'] |
| 52 | + $replica_host_value = $old_pe_conf['params']['replica_host'] |
| 53 | + $primary_postgresql_host_value = $old_pe_conf['params']['primary_postgresql_host'] |
| 54 | + $replica_postgresql_host_value = $old_pe_conf['params']['replica_postgresql_host'] |
| 55 | + $compilers_value = $old_pe_conf['params']['compilers'] |
| 56 | + $legacy_compilers_value = $old_pe_conf['params']['legacy_compilers'] |
| 57 | + |
| 58 | + $old_primary_host_string = !empty($old_primary_host_value) ? { |
| 59 | + true => $old_primary_host_value, |
| 60 | + default => '' |
| 61 | + } |
| 62 | + |
| 63 | + $replica_host_string = !empty($replica_host_value) ? { |
| 64 | + true => $replica_host_value, |
| 65 | + default => '' |
| 66 | + } |
| 67 | + |
| 68 | + $primary_postgresql_host_string = !empty($primary_postgresql_host_value) ? { |
| 69 | + true => $primary_postgresql_host_value, |
| 70 | + default => '' |
| 71 | + } |
| 72 | + |
| 73 | + $replica_postgresql_host_string = !empty($replica_postgresql_host_value) ? { |
| 74 | + true => $replica_postgresql_host_value, |
| 75 | + default => '' |
| 76 | + } |
| 77 | + |
| 78 | + $compilers_string = !empty($compilers_value) ? { |
| 79 | + true => $compilers_value.filter |$node| { !empty($node) }.join(','), |
| 80 | + default => '' |
| 81 | + } |
| 82 | + |
| 83 | + $legacy_compilers_string = !empty($legacy_compilers_value) ? { |
| 84 | + true => $legacy_compilers_value.filter |$node| { !empty($node) }.join(','), |
| 85 | + default => '' |
| 86 | + } |
| 87 | + |
| 88 | + $purge_components = [ |
| 89 | + $replica_host_string, |
| 90 | + $primary_postgresql_host_string, |
| 91 | + $replica_postgresql_host_string, |
| 92 | + $compilers_string, |
| 93 | + $legacy_compilers_string, |
| 94 | + $old_primary_host_string, |
| 95 | + ].filter |$component| { !empty($component) } |
| 96 | + |
| 97 | + out::message("purge_components: ${purge_components}") |
| 98 | +
|
| 99 | + if !empty($purge_components) { |
| 100 | + out::message('Purging nodes from old configuration individually') |
| 101 | + $purge_components.each |$component| { |
| 102 | + out::message("Purging component: ${component}") |
| 103 | + run_command("/opt/puppetlabs/bin/puppet node purge ${component}", $new_primary_host) |
| 104 | + } |
| 105 | + } else { |
| 106 | + out::message('No nodes to purge from old configuration') |
| 107 | + } |
| 108 | +
|
| 109 | + # if $replica_host { |
| 110 | + # run_plan('peadm::add_replica', { |
| 111 | + # primary_host => $new_primary_host, |
| 112 | + # replica_host => $replica_host, |
| 113 | + # }) |
| 114 | + # } |
| 115 | +
|
| 116 | + # if $upgrade_version and $upgrade_version != '' and !empty($upgrade_version) { |
| 117 | + # run_plan('peadm::upgrade', { |
| 118 | + # primary_host => $new_primary_host, |
| 119 | + # version => $upgrade_version, |
| 120 | + # download_mode => 'direct', |
| 121 | + # replica_host => $replica_host, |
| 122 | + # }) |
| 123 | + # } |
| 124 | +} |
0 commit comments