Skip to content

Commit ec4a2f1

Browse files
author
petergmurphy
committed
New changes
1 parent bba2ae0 commit ec4a2f1

File tree

6 files changed

+76
-60
lines changed

6 files changed

+76
-60
lines changed

manifests/setup/legacy_compiler_group.pp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010

1111
node_group { 'PE Legacy Compiler':
1212
ensure => 'present',
13-
parent => 'PE Infrastructure',
13+
parent => 'PE Master',
1414
purge_behavior => 'rule',
1515
rule => ['=', ['trusted', 'extensions', 'pp_auth_role'], 'pe_compiler_legacy'],
1616
classes => {
17-
'puppet_enterprise::profile::master' => {
18-
'puppetdb_host' => [$internal_compiler_a_pool_address, $internal_compiler_b_pool_address].filter |$_| { $_ },
19-
'puppetdb_port' => [8081],
20-
'replication_mode' => 'none',
21-
'code_manager_auto_configure' => true,
17+
'puppet_enterprise::profile::master' => {
18+
'puppetdb_host' => [$internal_compiler_a_pool_address, $internal_compiler_b_pool_address].filter |$_| { $_ },
19+
'puppetdb_port' => [8081],
2220
},
2321
},
2422
}

plans/convert.pp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,48 @@
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+
run_plan('peadm::modify_certificate', $modern_compilers_with_flag,
84+
primary_host => $primary_target,
85+
remove_extensions => [peadm::oid('peadm_legacy_compiler')],
86+
)
87+
}
88+
89+
if $legacy_compilers_with_flag.size > 0 {
90+
run_plan('peadm::modify_certificate', $legacy_compilers_with_flag,
91+
primary_host => $primary_target,
92+
add_extensions => {
93+
'pp_auth_role' => 'pe_compiler_legacy',
94+
},
95+
remove_extensions => [peadm::oid('peadm_legacy_compiler'), peadm::oid('pp_auth_role')],
96+
)
97+
}
98+
99+
run_task('peadm::puppet_runonce', peadm::flatten_compact([
100+
$compiler_targets,
101+
$legacy_compiler_targets,
102+
]))
103+
}
104+
63105
# Get trusted fact information for all compilers. Use peadm::certname() as
64106
# the hash key because the apply block below will break trying to parse the
65107
# $compiler_extensions variable if it has Target-type hash keys.
@@ -318,6 +360,9 @@
318360
run_command('systemctl restart pe-puppetserver.service pe-puppetdb.service', $compiler_targets)
319361
}
320362
363+
# Update PE Master rules to support legacy compilers
364+
run_task('peadm::update_pe_master_rules', $primary_target)
365+
321366
# Run puppet on all targets again to ensure everything is fully up-to-date
322367
run_task('peadm::puppet_runonce', $all_targets)
323368
}
@@ -333,7 +378,5 @@
333378
# lint:endignore
334379
}
335380
336-
run_task('peadm::update_pe_master_rules', $primary_target)
337-
338381
return("Conversion to peadm Puppet Enterprise ${arch['architecture']} completed.")
339382
}

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/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: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def get_pe_master_group_id
3131

3232
groups = JSON.parse(res.body)
3333
pe_master_group = groups.find { |group| group['name'] == 'PE Master' }
34-
35-
raise "Could not find PE Master group" unless pe_master_group
34+
35+
raise 'Could not find PE Master group' unless pe_master_group
3636
pe_master_group['id']
3737
rescue JSON::ParserError => e
3838
raise "Invalid JSON response from server: #{e.message}"
@@ -57,28 +57,30 @@ 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)
62-
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
69-
70-
# Recursively transform nested rules
71-
rule.map { |element| transform_rule(element) }
60+
def modify_pe_master_rules(rules)
61+
# If not an array, return as is
62+
return rules unless rules.is_a?(Array)
63+
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+
]
72+
73+
result
7274
end
7375

7476
def update_rules(group_id)
7577
net = https_client
7678
begin
7779
current_rules = get_current_rules(group_id)
78-
80+
7981
# Transform rules recursively to handle nested structures
80-
new_rules = transform_rule(current_rules)
81-
82+
new_rules = modify_pe_master_rules(current_rules)
83+
8284
# Update the group with the modified rules
8385
url = "/classifier-api/v1/groups/#{group_id}"
8486
req = Net::HTTP::Post.new(url)
@@ -114,4 +116,4 @@ def execute!
114116
Puppet.initialize_settings
115117
task = UpdatePeMasterRules.new(JSON.parse(STDIN.read))
116118
task.execute!
117-
end
119+
end

0 commit comments

Comments
 (0)