Skip to content

Commit ecd4ae5

Browse files
committed
(PE-36789) R10k Known hosts upgrade path
Adding optional parameter for r10k known hosts Alerting user to set known hosts if they are upgrading to or past 2023.3
1 parent c45b84c commit ecd4ae5

File tree

4 files changed

+72
-16
lines changed

4 files changed

+72
-16
lines changed

documentation/upgrade.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ Puppet Enterprise deployments provisioned using the peadm module can also be upg
44

55
## Usage
66

7-
The `peadm::upgrade` plan requires as input the version of PE to upgrade to, and the names of each PE infrastructure host. Primary, replica, compilers, etc.
7+
The `peadm::upgrade` plan requires as input the version of PE to upgrade to, and the names of each PE infrastructure host. Primary, replica, compilers, etc.
88

9-
The following is an example parameters file for upgrading an Extra Large architecture deployment of PE 2021.0.1 to PE 2021.7.4.
9+
Please note that when upgrading from before 2023.3 to 2023.3 or above and you are using code manager, it is nessesary to provide known hosts for r10k. r10k_known_hosts is an optional parameter and is only required one time when upgrading to 2023.3 or beyond. Subsequent upgrades will already have this and wont be required again.
10+
11+
The following is an example parameters file for upgrading an Extra Large architecture deployment of PE 2023.2.0 to PE 2023.3.0.
1012

1113
```json
1214
{
13-
"version": "2021.7.4",
15+
"version": "2023.3.0",
1416
"primary_host": "pe-master-09a40c-0.us-west1-a.c.reidmv-peadm.internal",
1517
"primary_postgresql_host": "pe-psql-09a40c-0.us-west1-a.c.reidmv-peadm.internal",
1618
"replica_host": "pe-master-09a40c-1.us-west1-b.c.reidmv-peadm.internal",
@@ -20,6 +22,10 @@ The following is an example parameters file for upgrading an Extra Large archite
2022
"pe-compiler-09a40c-1.us-west1-b.c.reidmv-peadm.internal",
2123
"pe-compiler-09a40c-2.us-west1-c.c.reidmv-peadm.internal",
2224
"pe-compiler-09a40c-3.us-west1-a.c.reidmv-peadm.internal"
25+
],
26+
"r10k_known_hosts": [
27+
{"name": "remotehostname", "type": "ssh-rsa", "key": "hash"},
28+
{"name": "remotehostname2", "type": "ssh-rsa", "key": "hash"}
2329
]
2430
}
2531
```
@@ -115,20 +121,20 @@ Note: it is assumed that the Puppet primary is in cluster A when the upgrade sta
115121
1. Shut down the `pe-puppetdb` service on the compilers in cluster B
116122
2. If different from the primary (replica), run the `install-puppet-enterprise` script for the new PE version on the PuppetDB PostgreSQL node for cluster B
117123
3. If different from the primary (replica), Run `puppet agent -t` on the PuppetDB PostgreSQL node for cluster B
118-
5. Run `puppet agent -t` on the primary to ensure orchestration services are configured and restarted before the next steps
119-
6. Perform the replica upgrade using `puppet infra upgrade replica` for the primary (replica)
120-
7. Perform the compiler upgrade using `puppet infra upgrade compiler` for the compilers in cluster B
124+
4. Run `puppet agent -t` on the primary to ensure orchestration services are configured and restarted before the next steps
125+
5. Perform the replica upgrade using `puppet infra upgrade replica` for the primary (replica)
126+
6. Perform the compiler upgrade using `puppet infra upgrade compiler` for the compilers in cluster B
121127

122128
**If Upgrading from 2019.5**
123129

124130
The following steps apply _only_ if upgrading from 2019.5 or older
125131

126132
1. Run `puppet infra run convert_legacy_compiler` for all compilers
127133
2. Modify the peadm node groups "PE Compiler Group A" and "PE Compiler Group B" as follows:
128-
* Re-parent the groups. They should be children of "PE Compiler"
129-
* Remove configuration data (Hiera data). Leave the classes and class parameters
130-
* Add the rule `trusted.extensions.pp_auth_role = pe_compiler`
131-
* Remove the rule `trusted.extensions."1.3.6.1.4.1.34380.1.1.9812" = puppet/compiler`
134+
* Re-parent the groups. They should be children of "PE Compiler"
135+
* Remove configuration data (Hiera data). Leave the classes and class parameters
136+
* Add the rule `trusted.extensions.pp_auth_role = pe_compiler`
137+
* Remove the rule `trusted.extensions."1.3.6.1.4.1.34380.1.1.9812" = puppet/compiler`
132138

133139
**Phase 4: resume puppet service**
134140

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function peadm::check_version_and_known_hosts(
2+
String $target_version,
3+
Optional[Peadm::Known_hosts] $r10k_known_hosts = undef,
4+
) {
5+
$version_check = SemVer($target_version) >= SemVer('2023.3.0')
6+
7+
out::message("Version check: ${version_check}")
8+
9+
# If the version is 2023.3 or greater and known_hosts is undef, print a message
10+
if ($version_check and $r10k_known_hosts == undef) {
11+
out::message("URGENT UPGRADE NOTICE:\nWhen you are upgrading to PE 2023.3 or later, it's crucial to ensure that the 'known_hosts' parameter for R10k is populated. Starting from PE 2023.3, Code Manager will not operate correctly without this. For more information, see https://puppet.com/docs/pe/2023.3/code_mgr_config.html#known-hosts-parameter")
12+
}
13+
}

plans/upgrade.pp

+33-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
# @param final_agent_state
2020
# Configures the state the puppet agent should be in on infrastructure nodes
2121
# after PE is upgraded successfully.
22-
#
22+
# @param r10k_known_hosts
23+
# Puppet Enterprise 2023.3+ requires host key verification for the
24+
# r10k_remote host when using ssh. you must provide \$r10k_known_hosts
25+
# information in the form of an array of hashes with 'name', 'type' and 'key'
26+
# information for hostname, key-type and public key.
27+
#
2328
plan peadm::upgrade (
2429
# Standard
2530
Peadm::SingleTargetSpec $primary_host,
@@ -33,11 +38,12 @@
3338
Optional[Peadm::SingleTargetSpec] $replica_postgresql_host = undef,
3439

3540
# Common Configuration
36-
Optional[Peadm::Pe_version] $version = undef,
37-
Optional[String] $pe_installer_source = undef,
38-
Optional[String] $compiler_pool_address = undef,
39-
Optional[String] $internal_compiler_a_pool_address = undef,
40-
Optional[String] $internal_compiler_b_pool_address = undef,
41+
Optional[Peadm::Pe_version] $version = undef,
42+
Optional[String] $pe_installer_source = undef,
43+
Optional[String] $compiler_pool_address = undef,
44+
Optional[String] $internal_compiler_a_pool_address = undef,
45+
Optional[String] $internal_compiler_b_pool_address = undef,
46+
Optional[Peadm::Known_hosts] $r10k_known_hosts = undef,
4147

4248
# Other
4349
Optional[String] $token_file = undef,
@@ -210,6 +216,25 @@
210216

211217
write_file($pe_conf, '/etc/puppetlabs/enterprise/conf.d/pe.conf', $target)
212218
}
219+
220+
if $r10k_known_hosts != undef {
221+
peadm::flatten_compact([
222+
$primary_target,
223+
]).each |$target| {
224+
$current_pe_conf = run_task('peadm::read_file', $target,
225+
path => '/etc/puppetlabs/enterprise/conf.d/pe.conf',
226+
).first['content']
227+
228+
$pe_conf = stdlib::to_json_pretty($current_pe_conf ? {
229+
undef => {},
230+
default => stdlib::parsehocon($current_pe_conf),
231+
} + {
232+
'puppet_enterprise::profile::master::r10k_known_hosts' => $r10k_known_hosts,
233+
})
234+
235+
write_file($pe_conf, '/etc/puppetlabs/enterprise/conf.d/pe.conf', $target)
236+
}
237+
}
213238
}
214239

215240
peadm::plan_step('upgrade-primary') || {
@@ -391,5 +416,7 @@
391416
)
392417
}
393418

419+
peadm::check_version_and_known_hosts($_version, $r10k_known_hosts)
420+
394421
return("Upgrade of Puppet Enterprise ${arch['architecture']} completed.")
395422
}

types/known_hosts.pp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type Peadm::Known_hosts = Array[
2+
Struct[
3+
'title' => Optional[String[1]],
4+
'ensure' => Optional[Enum['present','absent']],
5+
'name' => String[1],
6+
'type' => String[1],
7+
'key' => String[1],
8+
'host_aliases' => Optional[Variant[String[1],Array[String[1]]]],
9+
]
10+
]

0 commit comments

Comments
 (0)