Skip to content

Commit 7c6170f

Browse files
author
petergmurphy
committed
New changes
1 parent bba2ae0 commit 7c6170f

File tree

6 files changed

+195
-47
lines changed

6 files changed

+195
-47
lines changed

plans/convert.pp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,54 @@
6060

6161
out::message('# Gathering information')
6262

63+
$cert_extensions_temp = run_task('peadm::cert_data', $all_targets).reduce({}) |$memo,$result| {
64+
$memo + { $result.target.peadm::certname() => $result['extensions'] }
65+
}
66+
67+
# Add legacy compiler role to compilers that are missing it
68+
$compilers_with_legacy_compiler_flag = $cert_extensions_temp.filter |$name,$exts| {
69+
($name in $compiler_targets.map |$t| { $t.name } or $name in $legacy_compiler_targets.map |$t| { $t.name }) and
70+
($exts[peadm::oid('peadm_legacy_compiler')] != undef)
71+
}
72+
73+
if $compilers_with_legacy_compiler_flag.size > 0 {
74+
$legacy_compilers_with_flag = $compilers_with_legacy_compiler_flag.filter |$name,$exts| {
75+
$exts[peadm::oid('peadm_legacy_compiler')] == 'true'
76+
}.keys
77+
78+
$modern_compilers_with_flag = $compilers_with_legacy_compiler_flag.filter |$name,$exts| {
79+
$exts[peadm::oid('peadm_legacy_compiler')] == 'false'
80+
}.keys
81+
82+
if $modern_compilers_with_flag.size > 0 {
83+
out::message('MODERN COMPILERS: Beginning removal of legacy compiler flag')
84+
out::message($modern_compilers_with_flag)
85+
run_plan('peadm::modify_certificate', $modern_compilers_with_flag,
86+
primary_host => $primary_target,
87+
remove_extensions => [peadm::oid('peadm_legacy_compiler')],
88+
)
89+
out::message('MODERN COMPILERS: Removed legacy compiler flag')
90+
}
91+
92+
if $legacy_compilers_with_flag.size > 0 {
93+
out::message('LEGACY COMPILERS: Beginning addition of legacy compiler role and removal of legacy compiler flag')
94+
out::message($legacy_compilers_with_flag)
95+
run_plan('peadm::modify_certificate', $legacy_compilers_with_flag,
96+
primary_host => $primary_target,
97+
add_extensions => {
98+
'pp_auth_role' => 'pe_compiler_legacy',
99+
},
100+
remove_extensions => [peadm::oid('peadm_legacy_compiler'), peadm::oid('pp_auth_role')],
101+
)
102+
out::message('LEGACY COMPILERS: Added legacy compiler role and removed legacy compiler flag')
103+
}
104+
105+
run_task('peadm::puppet_runonce', peadm::flatten_compact([
106+
$compiler_targets,
107+
$legacy_compiler_targets,
108+
]))
109+
}
110+
63111
# Get trusted fact information for all compilers. Use peadm::certname() as
64112
# the hash key because the apply block below will break trying to parse the
65113
# $compiler_extensions variable if it has Target-type hash keys.
@@ -318,6 +366,9 @@
318366
run_command('systemctl restart pe-puppetserver.service pe-puppetdb.service', $compiler_targets)
319367
}
320368
369+
# Update PE Master rules to support legacy compilers
370+
run_task('peadm::update_pe_master_rules', $primary_target)
371+
321372
# Run puppet on all targets again to ensure everything is fully up-to-date
322373
run_task('peadm::puppet_runonce', $all_targets)
323374
}
@@ -333,7 +384,5 @@
333384
# lint:endignore
334385
}
335386
336-
run_task('peadm::update_pe_master_rules', $primary_target)
337-
338387
return("Conversion to peadm Puppet Enterprise ${arch['architecture']} completed.")
339388
}

plans/install.pp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@
143143
final_agent_state => $final_agent_state,
144144
)
145145

146-
run_task('peadm::update_pe_master_rules', $primary_host)
147-
148146
# Return a string banner reporting on what was done
149147
return([$install_result, $configure_result])
150148
}

plans/migrate_old.pp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# @summary Migrate a PE primary server to a new host
2+
#
3+
# @param old_primary_host
4+
# The existing PE primary server that will be migrated from
5+
# @param new_primary_host
6+
# The new server that will become the PE primary server
7+
# @param upgrade_version
8+
# Optional version to upgrade to after migration is complete
9+
#
10+
plan peadm::migrate (
11+
Peadm::SingleTargetSpec $old_primary_host,
12+
Peadm::SingleTargetSpec $new_primary_host,
13+
Optional[String] $upgrade_version = undef,
14+
Optional[Peadm::SingleTargetSpec] $replica_host = undef,
15+
) {
16+
peadm::assert_supported_bolt_version()
17+
18+
$backup_file = run_plan('peadm::backup', $old_primary_host, {
19+
backup_type => 'migration',
20+
})
21+
22+
$download_results = download_file($backup_file['path'], 'backup', $old_primary_host)
23+
$download_path = $download_results[0]['path']
24+
25+
$backup_filename = basename($backup_file['path'])
26+
$remote_backup_path = "/tmp/${backup_filename}"
27+
28+
upload_file($download_path, $remote_backup_path, $new_primary_host)
29+
30+
$old_primary_target = get_targets($old_primary_host)[0]
31+
$old_primary_password = peadm::get_pe_conf($old_primary_target)['console_admin_password']
32+
$old_pe_conf = run_task('peadm::get_peadm_config', $old_primary_target).first.value
33+
34+
out::message("old_pe_conf:${old_pe_conf}.")
35+
36+
# run_plan('peadm::install', {
37+
# primary_host => $new_primary_host,
38+
# console_password => $old_primary_password,
39+
# code_manager_auto_configure => true,
40+
# download_mode => 'direct',
41+
# version => $old_pe_conf['pe_version'],
42+
# })
43+
44+
# run_plan('peadm::restore', {
45+
# targets => $new_primary_host,
46+
# restore_type => 'migration',
47+
# input_file => $remote_backup_path,
48+
# })
49+
50+
# Use the old PE configuration to determine which nodes to purge
51+
$old_primary_host_value = $old_pe_conf['params']['primary_host']
52+
$replica_host_value = $old_pe_conf['params']['replica_host']
53+
$primary_postgresql_host_value = $old_pe_conf['params']['primary_postgresql_host']
54+
$replica_postgresql_host_value = $old_pe_conf['params']['replica_postgresql_host']
55+
$compilers_value = $old_pe_conf['params']['compilers']
56+
$legacy_compilers_value = $old_pe_conf['params']['legacy_compilers']
57+
58+
$old_primary_host_string = !empty($old_primary_host_value) ? {
59+
true => $old_primary_host_value,
60+
default => ''
61+
}
62+
63+
$replica_host_string = !empty($replica_host_value) ? {
64+
true => $replica_host_value,
65+
default => ''
66+
}
67+
68+
$primary_postgresql_host_string = !empty($primary_postgresql_host_value) ? {
69+
true => $primary_postgresql_host_value,
70+
default => ''
71+
}
72+
73+
$replica_postgresql_host_string = !empty($replica_postgresql_host_value) ? {
74+
true => $replica_postgresql_host_value,
75+
default => ''
76+
}
77+
78+
$compilers_string = !empty($compilers_value) ? {
79+
true => $compilers_value.filter |$node| { !empty($node) }.join(','),
80+
default => ''
81+
}
82+
83+
$legacy_compilers_string = !empty($legacy_compilers_value) ? {
84+
true => $legacy_compilers_value.filter |$node| { !empty($node) }.join(','),
85+
default => ''
86+
}
87+
88+
$purge_components = [
89+
$replica_host_string,
90+
$primary_postgresql_host_string,
91+
$replica_postgresql_host_string,
92+
$compilers_string,
93+
$legacy_compilers_string,
94+
$old_primary_host_string,
95+
].filter |$component| { !empty($component) }
96+
97+
out::message("purge_components: ${purge_components}")
98+
99+
if !empty($purge_components) {
100+
out::message('Purging nodes from old configuration individually')
101+
$purge_components.each |$component| {
102+
out::message("Purging component: ${component}")
103+
run_command("/opt/puppetlabs/bin/puppet node purge ${component}", $new_primary_host)
104+
}
105+
} else {
106+
out::message('No nodes to purge from old configuration')
107+
}
108+
109+
# if $replica_host {
110+
# run_plan('peadm::add_replica', {
111+
# primary_host => $new_primary_host,
112+
# replica_host => $replica_host,
113+
# })
114+
# }
115+
116+
# if $upgrade_version and $upgrade_version != '' and !empty($upgrade_version) {
117+
# run_plan('peadm::upgrade', {
118+
# primary_host => $new_primary_host,
119+
# version => $upgrade_version,
120+
# download_mode => 'direct',
121+
# replica_host => $replica_host,
122+
# })
123+
# }
124+
}

plans/subplans/configure.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,9 @@
174174
$legacy_compiler_targets,
175175
]))
176176

177+
# Update PE Master rules to support legacy compilers
178+
run_task('peadm::update_pe_master_rules', $primary_host)
179+
run_task('peadm::puppet_runonce', $legacy_compiler_targets)
180+
177181
return("Configuration of Puppet Enterprise ${arch['architecture']} succeeded.")
178182
}

plans/upgrade.pp

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -146,41 +146,12 @@
146146
($exts[peadm::oid('peadm_legacy_compiler')] != undef)
147147
}
148148

149-
run_task('peadm::update_pe_master_rules', $primary_target)
150-
151149
if $compilers_with_legacy_compiler_flag.size > 0 {
152-
$legacy_compilers = $compilers_with_legacy_compiler_flag.filter |$name,$exts| {
153-
$exts[peadm::oid('peadm_legacy_compiler')] == 'true'
154-
}.keys
155-
156-
$modern_compilers = $compilers_with_legacy_compiler_flag.filter |$name,$exts| {
157-
$exts[peadm::oid('peadm_legacy_compiler')] == 'false'
158-
}.keys
159-
160-
if $modern_compilers.size > 0 {
161-
out::message('MODERN COMPILERS: Beginning removal of legacy compiler flag')
162-
out::message($modern_compilers)
163-
run_plan('peadm::modify_certificate', $modern_compilers,
164-
primary_host => $primary_target,
165-
remove_extensions => [peadm::oid('peadm_legacy_compiler')],
166-
)
167-
out::message('MODERN COMPILERS: Removed legacy compiler flag')
168-
}
169-
170-
if $legacy_compilers.size > 0 {
171-
out::message('LEGACY COMPILERS: Beginning addition of legacy compiler role and removal of legacy compiler flag')
172-
out::message($legacy_compilers)
173-
run_plan('peadm::modify_certificate', $legacy_compilers,
174-
primary_host => $primary_target,
175-
add_extensions => {
176-
'pp_auth_role' => 'pe_compiler_legacy',
177-
},
178-
remove_extensions => [peadm::oid('peadm_legacy_compiler'), peadm::oid('pp_auth_role')],
179-
)
180-
out::message('LEGACY COMPILERS: Added legacy compiler role and removed legacy compiler flag')
181-
}
150+
fail_plan('Please run the Convert plan to convert your Puppet infrastructure to be managed by PEADM.')
182151
}
183152

153+
run_task('peadm::update_pe_master_rules', $primary_target)
154+
184155
# Gather certificate extension information from all systems
185156
$cert_extensions = run_task('peadm::cert_data', $all_targets).reduce({}) |$memo,$result| {
186157
$memo + { $result.target.peadm::certname => $result['extensions'] }

tasks/update_pe_master_rules.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ def get_current_rules(group_id)
5757
raise "Error fetching rules: #{e.message}"
5858
end
5959

60-
def transform_rule(rule)
61-
return rule unless rule.is_a?(Array)
60+
def modify_pe_master_rules(rules)
61+
# If not an array, return as is
62+
return rules unless rules.is_a?(Array)
6263

63-
if rule[0] == '=' &&
64-
rule[1].is_a?(Array) &&
65-
rule[1] == ['trusted', 'extensions', 'pp_auth_role'] &&
66-
rule[2] == 'pe_compiler'
67-
return ['~', ['trusted', 'extensions', 'pp_auth_role'], '^pe_compiler(?:_legacy)?$']
68-
end
64+
# Make a copy of the rules to avoid modifying the original
65+
result = rules.dup
66+
67+
result[1] = [
68+
'or',
69+
['=', ['trusted', 'extensions', 'pp_auth_role'], 'pe_compiler'],
70+
['=', ['trusted', 'extensions', 'pp_auth_role'], 'pe_compiler_legacy']
71+
]
6972

70-
# Recursively transform nested rules
71-
rule.map { |element| transform_rule(element) }
73+
result
7274
end
7375

7476
def update_rules(group_id)
@@ -77,7 +79,7 @@ def update_rules(group_id)
7779
current_rules = get_current_rules(group_id)
7880

7981
# Transform rules recursively to handle nested structures
80-
new_rules = transform_rule(current_rules)
82+
new_rules = modify_pe_master_rules(current_rules)
8183

8284
# Update the group with the modified rules
8385
url = "/classifier-api/v1/groups/#{group_id}"

0 commit comments

Comments
 (0)