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