|
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 |
| - |
| 1 | +# @summary Add a replica to a PE architecture or replace an existing one. |
| 2 | +# Supported use cases: |
| 3 | +# 1: the replica is gone, |
| 4 | +# 2: there is no replica, |
| 5 | +# both use cases: we have a fresh new VM we want to provision the replica to. |
| 6 | +# @param primary_host - The hostname and certname of the primary Puppet server |
| 7 | +# @param replica_host - The hostname and certname of the replica VM |
| 8 | +# @param replica_postgresql_host - The hostname and certname of the host with the replica PE-PosgreSQL database. |
| 9 | +# Can be a separate host in an XL architecture, or the replica host in standard or Large. |
5 | 10 | plan peadm::add_replica(
|
6 | 11 | Peadm::SingleTargetSpec $primary_host,
|
7 | 12 | Peadm::SingleTargetSpec $replica_host,
|
|
16 | 21 | $primary_avail_group_letter = $certdata['extensions'][peadm::oid('peadm_availability_group')]
|
17 | 22 | $replica_avail_group_letter = $primary_avail_group_letter ? { 'A' => 'B', default => 'A' }
|
18 | 23 |
|
19 |
| - # Stop puppet.service on replica postgresql host |
20 |
| - run_command('systemctl stop puppet.service', $replica_postgresql_target) |
| 24 | + # Stop puppet.service on replica postgresql host. Catch errors in case no puppet service is running |
| 25 | + run_command('systemctl stop puppet.service', $replica_postgresql_target, _catch_errors => true) |
21 | 26 |
|
22 | 27 | # stop pe-postgresql.service on replica postgresql host
|
23 |
| - run_command('systemctl stop pe-postgresql.service', $replica_postgresql_target) |
| 28 | + run_command('systemctl stop pe-postgresql.service', $replica_postgresql_target, _catch_errors => true) |
24 | 29 |
|
25 |
| - run_command("puppet infrastructure forget ${replica_target.peadm::certname()}", $primary_target) |
| 30 | + run_command("puppet infrastructure forget ${replica_target.peadm::certname()}", $primary_target, _catch_errors => true) |
26 | 31 |
|
27 | 32 | run_task('peadm::agent_install', $replica_target,
|
28 | 33 | server => $primary_target.peadm::certname(),
|
29 | 34 | install_flags => [
|
30 |
| - "extension_requests:${peadm::oid('peadm_role')}='puppet/server'", |
| 35 | + "extension_requests:${peadm::oid('peadm_role')}=puppet/server", |
31 | 36 | "extension_requests:${peadm::oid('peadm_availability_group')}=${replica_avail_group_letter}",
|
32 | 37 | "main:certname=${replica_target.peadm::certname()}",
|
33 | 38 | ],
|
34 | 39 | )
|
35 | 40 |
|
| 41 | + # run puppet agent once ignoring possible cert errors |
| 42 | + run_task('peadm::puppet_runonce', $replica_target, _catch_errors => true) |
| 43 | + |
| 44 | + # If necessary, manually submit a CSR |
| 45 | + # ignoring errors to simplify logic |
| 46 | + run_task('peadm::submit_csr', $replica_target, _catch_errors => true) |
| 47 | + |
| 48 | + # On primary, if necessary, sign the certificate request |
| 49 | + run_task('peadm::sign_csr', $primary_target, certnames => [$replica_target.peadm::certname()] ) |
| 50 | + |
| 51 | + # On <replica_target>, run the puppet agent |
36 | 52 | run_task('peadm::puppet_runonce', $replica_target)
|
37 | 53 |
|
38 | 54 | # On the PE-PostgreSQL server in the <replacement-avail-group-letter> group
|
|
44 | 60 |
|
45 | 61 | # pe-puppetdb-pe-puppetdb-map <replacement-replica-fqdn> pe-puppetdb
|
46 | 62 | # pe-puppetdb-pe-puppetdb-migrator-map <replacement-replica-fqdn> pe-puppetdb-migrator
|
47 |
| - apply($replica_postgresql_target) { |
| 63 | + apply($replica_postgresql_target, _catch_errors => true) { |
48 | 64 | file_line { 'pe-puppetdb-pe-puppetdb-map':
|
49 | 65 | path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf',
|
50 | 66 | line => "pe-puppetdb-pe-puppetdb-map ${replica_target.peadm::certname()} pe-puppetdb",
|
|
56 | 72 | }
|
57 | 73 |
|
58 | 74 | # Restart pe-postgresql.service
|
59 |
| - run_command('systemctl restart pe-postgresql.service', $replica_postgresql_target) |
| 75 | + run_command('systemctl restart pe-postgresql.service', $replica_postgresql_target, _catch_errors => true) |
60 | 76 |
|
61 | 77 | # Provision the new system as a replica
|
62 | 78 | run_task('peadm::provision_replica', $primary_target,
|
|
70 | 86 | )
|
71 | 87 |
|
72 | 88 | # start puppet service on postgresql host
|
73 |
| - run_command('systemctl stop puppet.service', $replica_postgresql_target) |
| 89 | + run_command('systemctl start puppet.service', $replica_postgresql_target) |
74 | 90 |
|
75 | 91 |
|
76 | 92 | }
|
0 commit comments