|
| 1 | +# use case 1: the replica is gone, |
| 2 | +# use case 2: there is no replica, |
| 3 | +# both use cases: we have a fresh new VM we want to provision the replica to |
| 4 | + |
| 5 | +plan peadm::add_replica( |
| 6 | + Peadm::SingleTargetSpec $primary_host, |
| 7 | + Peadm::SingleTargetSpec $replica_host, |
| 8 | + Peadm::SingleTargetSpec $replica_postgresql_host, |
| 9 | +){ |
| 10 | + |
| 11 | + $primary_target = peadm::get_targets($primary_host, 1) |
| 12 | + $replica_target = peadm::get_targets($replica_host, 1) |
| 13 | + $replica_postgresql_target = peadm::get_targets($replica_postgresql_host, 1) |
| 14 | + |
| 15 | + $certdata = run_task('peadm::cert_data', $primary_target).first.value |
| 16 | + $primary_avail_group_letter = $certdata['extensions'][peadm::oid('peadm_availability_group')] |
| 17 | + $replica_avail_group_letter = $primary_avail_group_letter ? { 'A' => 'B', default => 'A' } |
| 18 | + |
| 19 | + # Stop puppet.service on replica postgresql host |
| 20 | + run_command('systemctl stop puppet.service', $replica_postgresql_target) |
| 21 | + |
| 22 | + # stop pe-postgresql.service on replica postgresql host |
| 23 | + run_command('systemctl stop pe-postgresql.service', $replica_postgresql_target) |
| 24 | + |
| 25 | + run_command("puppet infrastructure forget ${replica_target.peadm::certname()}", $primary_target) |
| 26 | + |
| 27 | + run_task('peadm::agent_install', $replica_target, |
| 28 | + server => $primary_target.peadm::certname(), |
| 29 | + install_flags => [ |
| 30 | + "extension_requests:${peadm::oid('peadm_role')}='puppet/server'", |
| 31 | + "extension_requests:${peadm::oid('peadm_availability_group')}=${replica_avail_group_letter}", |
| 32 | + "main:certname=${replica_target.peadm::certname()}", |
| 33 | + ], |
| 34 | + ) |
| 35 | + |
| 36 | + run_task('peadm::puppet_runonce', $replica_target) |
| 37 | + |
| 38 | + # On the PE-PostgreSQL server in the <replacement-avail-group-letter> group |
| 39 | + |
| 40 | + # Stop puppet.service |
| 41 | + run_command('systemctl stop puppet.service', $replica_postgresql_target) |
| 42 | + |
| 43 | + # Add the following two lines to /opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf |
| 44 | + |
| 45 | + # pe-puppetdb-pe-puppetdb-map <replacement-replica-fqdn> pe-puppetdb |
| 46 | + # pe-puppetdb-pe-puppetdb-migrator-map <replacement-replica-fqdn> pe-puppetdb-migrator |
| 47 | + apply($replica_postgresql_target) { |
| 48 | + file_line { 'pe-puppetdb-pe-puppetdb-map': |
| 49 | + path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf', |
| 50 | + line => "pe-puppetdb-pe-puppetdb-map ${replica_target.peadm::certname()} pe-puppetdb", |
| 51 | + } |
| 52 | + file_line { 'pe-puppetdb-pe-puppetdb-migrator-map': |
| 53 | + path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf', |
| 54 | + line => "pe-puppetdb-pe-puppetdb-migrator-map ${replica_target.peadm::certname()} pe-puppetdb-migrator", |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + # Restart pe-postgresql.service |
| 59 | + run_command('systemctl restart pe-postgresql.service', $replica_postgresql_target) |
| 60 | + |
| 61 | + # Provision the new system as a replica |
| 62 | + run_task('peadm::provision_replica', $primary_target, |
| 63 | + replica => $replica_target.peadm::certname(), |
| 64 | + # token_file => $token_file, |
| 65 | + |
| 66 | + # Race condition, where the provision command checks PuppetDB status and |
| 67 | + # probably gets "starting", but fails out because that's not "running". |
| 68 | + # Can remove flag when that issue is fixed. |
| 69 | + legacy => true, |
| 70 | + ) |
| 71 | + |
| 72 | + # start puppet service on postgresql host |
| 73 | + run_command('systemctl stop puppet.service', $replica_postgresql_target) |
| 74 | + |
| 75 | + |
| 76 | +} |
0 commit comments