Skip to content

Commit dd2b53b

Browse files
committed
Preserve existing csr_attributes data
In the event a csr_attributes.yaml file is already present, don't overwrite it; instead, merge in the values we need to any values already present.
1 parent 7d0e0c3 commit dd2b53b

File tree

3 files changed

+52
-33
lines changed

3 files changed

+52
-33
lines changed

plans/action/install.pp

+19-28
Original file line numberDiff line numberDiff line change
@@ -179,38 +179,29 @@
179179
upload_path => $upload_tarball_path,
180180
)
181181

182-
# Create csr_attributes.yaml files for the nodes that need them
183-
# There is a problem with OID names in csr_attributes.yaml for some
184-
# installs, e.g. PE 2019.0.1, PUP-9746. Use the raw OIDs for now.
185-
186-
run_task('peadm::mkdir_p_file', $master_target,
187-
path => '/etc/puppetlabs/puppet/csr_attributes.yaml',
188-
content => @("HEREDOC"),
189-
---
190-
extension_requests:
191-
${peadm::oid('peadm_role')}: "puppet/master"
192-
${peadm::oid('peadm_availability_group')}: "A"
193-
| HEREDOC
182+
# Create csr_attributes.yaml files for the nodes that need them. Ensure that
183+
# if a csr_attributes.yaml file is already present, the values we need are
184+
# merged with the existing values.
185+
186+
run_plan('peadm::util::insert_csr_extensions', $master_target,
187+
extensions => {
188+
peadm::oid('peadm_role') => 'puppet/master',
189+
peadm::oid('peadm_availability_group') => 'A',
190+
},
194191
)
195192

196-
run_task('peadm::mkdir_p_file', $puppetdb_database_target,
197-
path => '/etc/puppetlabs/puppet/csr_attributes.yaml',
198-
content => @("HEREDOC"),
199-
---
200-
extension_requests:
201-
${peadm::oid('peadm_role')}: "puppet/puppetdb-database"
202-
${peadm::oid('peadm_availability_group')}: "A"
203-
| HEREDOC
193+
run_plan('peadm::util::insert_csr_extensions', $puppetdb_database_target,
194+
extensions => {
195+
peadm::oid('peadm_role') => 'puppet/puppetdb-database',
196+
peadm::oid('peadm_availability_group') => 'A',
197+
},
204198
)
205199

206-
run_task('peadm::mkdir_p_file', $puppetdb_database_replica_target,
207-
path => '/etc/puppetlabs/puppet/csr_attributes.yaml',
208-
content => @("HEREDOC"),
209-
---
210-
extension_requests:
211-
${peadm::oid('peadm_role')}: "puppet/puppetdb-database"
212-
${peadm::oid('peadm_availability_group')}: "B"
213-
| HEREDOC
200+
run_plan('peadm::util::insert_csr_extensions', $puppetdb_database_replica_target,
201+
extensions => {
202+
peadm::oid('peadm_role') => 'puppet/puppetdb-database',
203+
peadm::oid('peadm_availability_group') => 'B',
204+
},
214205
)
215206

216207
# Get the master installation up and running. The installer will

plans/util/insert_csr_extensions.pp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plan peadm::util::insert_csr_extensions (
2+
TargetSpec $targets,
3+
Hash $extensions,
4+
) {
5+
get_targets($targets).each |$target| {
6+
$csr_attributes_data = ($csr_file = run_task('peadm::read_file', $target,
7+
path => '/etc/puppetlabs/puppet/csr_attributes.yaml',
8+
).first['content']) ? {
9+
undef => { },
10+
default => $csr_file.parseyaml,
11+
}
12+
13+
run_task('peadm::mkdir_p_file', $target,
14+
path => '/etc/puppetlabs/puppet/csr_attributes.yaml',
15+
content => $csr_attributes_data.deep_merge({'extensions' => $extensions}).to_yaml,
16+
)
17+
}
18+
}

tasks/read_file.rb

+15-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22

33
require 'json'
44

5-
params = JSON.parse(STDIN.read)
6-
content = File.read(params['path'])
7-
result = { 'content' => content }.to_json
8-
9-
puts result
5+
begin
6+
params = JSON.parse(STDIN.read)
7+
content = File.read(params['path'])
8+
rescue StandardError => err
9+
result = {
10+
'content' => nil,
11+
'error' => err.message,
12+
}
13+
else
14+
result = {
15+
'content' => content
16+
}
17+
ensure
18+
puts result.to_json
19+
end

0 commit comments

Comments
 (0)