Skip to content

Commit b81d45c

Browse files
committedFeb 20, 2020
Fixups and DRY cleanup
* When copying private key and license, flatten and compact target list - Bolt doesn't play well with undef as a target * Because the file/content pattern is being used twice now, relegate details to a function (DRY)
1 parent 2e20939 commit b81d45c

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed
 

Diff for: ‎functions/file_or_content.pp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function peadm::file_or_content(
2+
String $param_name,
3+
String $file,
4+
String $content,
5+
) {
6+
7+
$value = [
8+
$file,
9+
$content,
10+
].peadm::flatten_compact.size ? {
11+
0 => undef, # no key data supplied
12+
2 => fail("Must specify either one or neither of ${param_name}_file and ${param_name}_content; not both"),
13+
1 => $file ? {
14+
String => file($file), # file path supplied, read data from file
15+
undef => $content, # content supplied directly, use as-is
16+
},
17+
}
18+
19+
}

Diff for: ‎plans/action/install.pp

+12-25
Original file line numberDiff line numberDiff line change
@@ -100,32 +100,13 @@
100100

101101
$dns_alt_names_csv = $dns_alt_names.reduce |$csv,$x| { "${csv},${x}" }
102102

103-
# Process user input for r10k private key (content or file) and set
103+
# Process user input for r10k private key (file or content) and set
104104
# appropriate value in $r10k_private_key. The value of this variable should
105105
# either be undef or else the key content to write.
106-
$r10k_private_key = [
107-
$r10k_private_key_file,
108-
$r10k_private_key_content,
109-
].peadm::flatten_compact.size ? {
110-
0 => undef, # no key data supplied
111-
2 => fail('Must specify either one or neither of r10k_private_key_file and r10k_private_key_content; not both'),
112-
1 => $r10k_private_key_file ? {
113-
String => file($r10k_private_key_file), # key file path supplied, read data from file
114-
undef => $r10k_private_key_content, # key content supplied directly, use as-is
115-
},
116-
}
106+
$r10k_private_key = peadm::file_or_content('r10k_private_key', $r10k_private_key_file, $r10k_private_key_content)
117107

118-
$license_key = [
119-
$license_key_file,
120-
$license_key_content,
121-
].peadm::flatten_compact.size ? {
122-
0 => undef, # no key data supplied
123-
2 => fail('Must specify either one or neither of license_key_file and license_key_content; not both'),
124-
1 => $license_key_file ? {
125-
String => file($license_key_file), # key file path supplied, read data from file
126-
undef => $license_key_content, # key content supplied directly, use as-is
127-
},
128-
}
108+
# Same for license key
109+
$license_key = peadm::file_or_content('license_key', $license_key_file, $license_key_content)
129110

130111
$precheck_results = run_task('peadm::precheck', $all_targets)
131112
$platform = $precheck_results.first['platform'] # Assume the platform of the first result correct
@@ -233,7 +214,10 @@
233214
}
234215
235216
if $r10k_private_key {
236-
run_task('peadm::mkdir_p_file', [$master_target, $master_replica_target],
217+
run_task('peadm::mkdir_p_file', peadm::flatten_compact([
218+
$master_target,
219+
$master_replica_target,
220+
]),
237221
path => '/etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa',
238222
owner => 'pe-puppet',
239223
group => 'pe-puppet',
@@ -243,7 +227,10 @@
243227
}
244228
245229
if $license_key {
246-
run_task('peadm::mkdir_p_file', [$master_target, $master_replica_target],
230+
run_task('peadm::mkdir_p_file', peadm::flatten_compact([
231+
$master_target,
232+
$master_replica_target,
233+
]),
247234
path => '/etc/puppetlabs/license.key',
248235
owner => 'pe-puppet',
249236
group => 'pe-puppet',

0 commit comments

Comments
 (0)
Please sign in to comment.