|
40 | 40 | out::message("Operating mode overridden by parameter mode set to ${mode}")
|
41 | 41 | } else {
|
42 | 42 | # If array is empty then no external databases were previously configured
|
43 |
| - $no_external_db = peadm::flatten_compact([$primary_postgresql_host, $replica_postgresql_host]).empty |
| 43 | + $no_external_db = peadm::flatten_compact([ |
| 44 | + $primary_postgresql_host, |
| 45 | + $replica_postgresql_host |
| 46 | + ]).empty |
44 | 47 |
|
45 | 48 | # Pick operating mode based on array check
|
46 | 49 | if $no_external_db {
|
|
53 | 56 |
|
54 | 57 | if $operating_mode == 'init' {
|
55 | 58 | # If no other PSQL node then match primary group letter
|
56 |
| - $avail_group_letter = peadm::flatten_compact($roles['server'].map |$k,$v| { if $v == $primary_host { $k } })[0] |
| 59 | + $avail_group_letter = peadm::flatten_compact($roles['server'].map |$k,$v| { |
| 60 | + if $v == $primary_host { |
| 61 | + $k |
| 62 | + } |
| 63 | + })[0] |
57 | 64 | # Assume PuppetDB backend hosted on Primary if in init mode
|
58 | 65 | $source_db_host = $primary_host
|
59 | 66 | } else {
|
|
65 | 72 | }
|
66 | 73 | })[0]
|
67 | 74 | # When in pair mode we assume the other PSQL node will serve as our source
|
68 |
| - $source_db_host = peadm::flatten_compact([$primary_postgresql_host, $replica_postgresql_host]).reject($targets.peadm::certname())[0] |
| 75 | + $source_db_host = peadm::flatten_compact([ |
| 76 | + $primary_postgresql_host, |
| 77 | + $replica_postgresql_host |
| 78 | + ]).reject($targets.peadm::certname())[0] |
69 | 79 | }
|
70 | 80 |
|
71 | 81 | out::message("Adding PostgreSQL server ${targets.peadm::certname()} to availability group ${avail_group_letter}")
|
|
84 | 94 | }
|
85 | 95 |
|
86 | 96 | # Stop Puppet to ensure catalogs are not being compiled for PE infrastructure nodes
|
87 |
| - run_command('systemctl stop puppet', peadm::flatten_compact([ |
| 97 | + run_command('systemctl stop puppet.service', peadm::flatten_compact([ |
88 | 98 | $targets,
|
89 | 99 | $compilers,
|
90 | 100 | $primary_target,
|
91 | 101 | $replica_target,
|
92 | 102 | $source_db_target
|
93 | 103 | ]))
|
94 | 104 |
|
95 |
| - # Stop frontend services that causes changes to PuppetDB backend when agents request |
96 |
| - # catalogs, except for primary because we need it for the next step |
97 |
| - run_command('systemctl stop pe-puppetserver pe-puppetdb', $compilers) |
| 105 | + # Stop frontend compiler services that causes changes to PuppetDB backend when |
| 106 | + # agents request catalogs |
| 107 | + run_command('systemctl stop pe-puppetserver.service pe-puppetdb.service', $compilers) |
98 | 108 |
|
99 | 109 | peadm::plan_step('replicate-db') || {
|
100 | 110 | # Replicate content from source to newly installed PSQL server
|
|
104 | 114 | run_task('peadm::puppet_runonce', $targets)
|
105 | 115 | }
|
106 | 116 |
|
107 |
| - # Now stop the rest of the services that can cause PuppetDB changes |
108 |
| - run_command('systemctl stop pe-puppetserver pe-puppetdb', peadm::flatten_compact([ |
109 |
| - $primary_target, |
110 |
| - $replica_target |
111 |
| - ])) |
112 |
| - |
113 |
| - # Update classification and database.ini setting |
114 | 117 | if $operating_mode == 'init' {
|
| 118 | + |
| 119 | + # Update classification and database.ini settings, assume a replica PSQL |
| 120 | + # does not exist |
115 | 121 | peadm::plan_step('update-classification') || {
|
116 | 122 | run_plan('peadm::util::update_classification', $primary_target,
|
117 | 123 | primary_postgresql_host => pick($primary_postgresql_host, $targets),
|
118 | 124 | peadm_config => $peadm_config
|
119 | 125 | )
|
120 | 126 | }
|
| 127 | + |
121 | 128 | peadm::plan_step('update-db-settings') || {
|
122 | 129 | run_plan('peadm::util::update_db_setting', peadm::flatten_compact([
|
123 | 130 | $compilers,
|
|
127 | 134 | primary_postgresql_host => $targets,
|
128 | 135 | peadm_config => $peadm_config
|
129 | 136 | )
|
| 137 | + |
| 138 | + # (Re-)Start PuppetDB now that we are done making modifications |
| 139 | + run_command('systemctl restart pe-puppetdb.service', peadm::flatten_compact([ |
| 140 | + $primary_target, |
| 141 | + $replica_target |
| 142 | + ])) |
| 143 | + } |
| 144 | + |
| 145 | + # Clean up old puppetdb database on primary and those which were copied to |
| 146 | + # new host. |
| 147 | + peadm::plan_step('cleanup-db') || { |
| 148 | + |
| 149 | + $target_db_purge = [ |
| 150 | + 'pe-activity', |
| 151 | + 'pe-classifier', |
| 152 | + 'pe-inventory', |
| 153 | + 'pe-orchestrator', |
| 154 | + 'pe-rbac' |
| 155 | + ] |
| 156 | + |
| 157 | + # If a primary replica exists then pglogical is enabled and will prevent |
| 158 | + # the clean up of databases on our target because it opens a connection. |
| 159 | + if $replica_host { |
| 160 | + run_plan('peadm::util::db_disable_pglogical', $targets, databases => $target_db_purge) |
| 161 | + } |
| 162 | + |
| 163 | + # Clean up old databases |
| 164 | + $clean_source = peadm::flatten_compact([ |
| 165 | + $source_db_target, |
| 166 | + $primary_target, |
| 167 | + $replica_target |
| 168 | + ]) |
| 169 | + |
| 170 | + run_plan('peadm::util::db_purge', $clean_source, databases => ['pe-puppetdb']) |
| 171 | + run_plan('peadm::util::db_purge', $targets, databases => $target_db_purge) |
130 | 172 | }
|
131 | 173 | } else {
|
132 | 174 | peadm::plan_step('update-classification') || {
|
|
136 | 178 | peadm_config => $peadm_config
|
137 | 179 | )
|
138 | 180 | }
|
| 181 | + |
139 | 182 | # Plan needs to know which node is being added as well as primary and
|
140 | 183 | # replica designation
|
141 | 184 | peadm::plan_step('update-db-settings') || {
|
|
149 | 192 | replica_postgresql_host => pick($replica_postgresql_host, $targets),
|
150 | 193 | peadm_config => $peadm_config
|
151 | 194 | )
|
152 |
| - } |
153 |
| - } |
154 | 195 |
|
155 |
| - # If in mode init clean up old puppetdb database on primary and those which |
156 |
| - # were copied to new host. |
157 |
| - if $operating_mode == 'init' { |
158 |
| - |
159 |
| - $target_db_purge = [ |
160 |
| - 'pe-activity', |
161 |
| - 'pe-classifier', |
162 |
| - 'pe-inventory', |
163 |
| - 'pe-orchestrator', |
164 |
| - 'pe-rbac' |
165 |
| - ] |
166 |
| - |
167 |
| - # If a replica exists then pglogical is enabled and will prevent the clean up |
168 |
| - # of databases on our target because it opens a connection. |
| 196 | + # (Re-)Start PuppetDB now that we are done making modifications |
| 197 | + run_command('systemctl restart pe-puppetdb.service', peadm::flatten_compact([ |
| 198 | + $primary_target, |
| 199 | + $replica_target |
| 200 | + ])) |
| 201 | + } |
169 | 202 | peadm::plan_step('cleanup-db') || {
|
170 |
| - if $replica_host { |
171 |
| - run_plan('peadm::util::db_disable_pglogical', $targets, databases => $target_db_purge) |
172 |
| - } |
173 |
| - |
174 |
| - # Clean up old databases |
175 |
| - $clean_source = peadm::flatten_compact([$source_db_target, $primary_target, $replica_target]) |
176 |
| - run_plan('peadm::util::db_purge', $clean_source, databases => ['pe-puppetdb']) |
177 |
| - run_plan('peadm::util::db_purge', $targets, databases => $target_db_purge) |
| 203 | + out::message("No databases to cleanup when in ${operating_mode}") |
178 | 204 | }
|
179 |
| - } else { |
180 |
| - peadm::plan_step('cleanup-db') || {} |
181 |
| - out::message("No databases to cleanup when in ${operating_mode}") |
182 | 205 | }
|
183 | 206 |
|
184 |
| - # Start services so catalogs can once again be compiled |
185 |
| - run_command('systemctl start pe-puppetserver pe-puppetdb', peadm::flatten_compact([ |
186 |
| - $compilers, |
187 |
| - $primary_target, |
188 |
| - $replica_target |
189 |
| - ])) |
| 207 | + # Start frontend compiler services so catalogs can once again be compiled by |
| 208 | + # agents |
| 209 | + run_command('systemctl start pe-puppetserver.service pe-puppetdb.service', $compilers) |
190 | 210 |
|
191 | 211 |
|
192 | 212 | peadm::plan_step('finalize') || {
|
|
199 | 219 | ]))
|
200 | 220 |
|
201 | 221 | # Start Puppet agent
|
202 |
| - run_command('systemctl start puppet', peadm::flatten_compact([ |
| 222 | + run_command('systemctl start puppet.service', peadm::flatten_compact([ |
203 | 223 | $targets,
|
204 | 224 | $compilers,
|
205 | 225 | $primary_target,
|
|
0 commit comments