Skip to content

Commit df4835f

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 df4835f

File tree

7 files changed

+114
-16
lines changed

7 files changed

+114
-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

examples/upgrade.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "2023.3.0",
3+
"primary_host": "pe-master-09a40c-0.us-west1-a.c.reidmv-peadm.internal",
4+
"primary_postgresql_host": "pe-psql-09a40c-0.us-west1-a.c.reidmv-peadm.internal",
5+
"replica_host": "pe-master-09a40c-1.us-west1-b.c.reidmv-peadm.internal",
6+
"replica_postgresql_host": "pe-psql-09a40c-1.us-west1-b.c.reidmv-peadm.internal",
7+
"compiler_hosts": [
8+
"pe-compiler-09a40c-0.us-west1-a.c.reidmv-peadm.internal",
9+
"pe-compiler-09a40c-1.us-west1-b.c.reidmv-peadm.internal",
10+
"pe-compiler-09a40c-2.us-west1-c.c.reidmv-peadm.internal",
11+
"pe-compiler-09a40c-3.us-west1-a.c.reidmv-peadm.internal"
12+
],
13+
"r10k_known_hosts": [
14+
{"name": "remotehostname", "type": "ssh-rsa", "key": "hash"},
15+
{"name": "remotehostname2", "type": "ssh-rsa", "key": "hash"}
16+
]
17+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# @summary Checks PE verison and warns about setting r10k_known_hosts
2+
# Checks if the current PE version is less than 2023.3.0 and the target version is greater than or equal to 2023.3.0
3+
# If both conditions are true and the r10k_known_hosts parameter is not defined, a warning message is displayed.
4+
# @param $current_version [String] The current PE version
5+
# @param $target_version [String] The target PE version
6+
# @param $r10k_known_hosts [Optional[Peadm::Known_hosts]] The r10k_known_hosts parameter
7+
function peadm::check_version_and_known_hosts(
8+
String $current_version,
9+
String $target_version,
10+
Optional[Peadm::Known_hosts] $r10k_known_hosts = undef,
11+
) {
12+
$version = '2023.3.0'
13+
$current_check = SemVer($current_version) < SemVer($version)
14+
$target_check = SemVer($target_version) >= SemVer($version)
15+
16+
# lint:ignore:140chars
17+
if ($current_check and $target_check and $r10k_known_hosts == undef) {
18+
out::message( @(HEREDOC/n)
19+
\nWARNING: Starting in PE 2023.3, SSH host key verification is required for Code Manager and r10k.\n
20+
To enable host key verification, you must define the puppet_enterprise::profile::master::r10k_known_hosts parameter with an array of hashes containing "name", "type", and "key" to specify your hostname, key type, and public key.\n
21+
If you currently use SSH protocol to allow r10k to access your remote Git repository, your Code Manager or r10k code management tool cannot function until you define the r10k_known_hosts parameter.\n
22+
HEREDOC
23+
)# lint:endignore
24+
}
25+
}

functions/get_pe_conf.pp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# @summary Returns the current pe.conf content as a hash
2+
# @param Target $target The target to run the task on
3+
function peadm::get_pe_conf(Target $target) {
4+
$current_pe_conf_content = run_task('peadm::read_file', $target, path => '/etc/puppetlabs/enterprise/conf.d/pe.conf').first['content']
5+
6+
# Parse the current pe.conf content and return the hash
7+
return $current_pe_conf_content ? {
8+
undef => {},
9+
default => stdlib::parsehocon($current_pe_conf_content),
10+
}
11+
}

functions/update_pe_conf.pp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# @summary Update the pe.conf file on a target with the provided hash
2+
# @param target [Bolt::Target] The target to update the pe.conf file on
3+
# @param updated_pe_conf_hash [Hash] The hash to update the pe.conf file with
4+
function peadm::update_pe_conf(Target $target, Hash $updated_pe_conf_hash) {
5+
# Convert the updated hash back to a pretty JSON string
6+
$updated_pe_conf_content = stdlib::to_json_pretty($updated_pe_conf_hash)
7+
8+
# Write the updated content back to pe.conf on the target
9+
write_file($updated_pe_conf_content, '/etc/puppetlabs/enterprise/conf.d/pe.conf', $target)
10+
}

plans/upgrade.pp

+25-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,17 @@
210216

211217
write_file($pe_conf, '/etc/puppetlabs/enterprise/conf.d/pe.conf', $target)
212218
}
219+
220+
if $r10k_known_hosts != undef {
221+
$current_pe_conf = peadm::get_pe_conf($primary_target)
222+
223+
# Append the r10k_known_hosts entry
224+
$updated_pe_conf = $current_pe_conf + {
225+
'puppet_enterprise::profile::master::r10k_known_hosts' => $r10k_known_hosts,
226+
}
227+
228+
peadm::update_pe_conf($primary_target, $updated_pe_conf)
229+
}
213230
}
214231

215232
peadm::plan_step('upgrade-primary') || {
@@ -391,5 +408,7 @@
391408
)
392409
}
393410

411+
peadm::check_version_and_known_hosts($current_pe_version, $_version, $r10k_known_hosts)
412+
394413
return("Upgrade of Puppet Enterprise ${arch['architecture']} completed.")
395414
}

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)