Skip to content

Commit 1d98389

Browse files
committed
Simplify r10k_private_key handling
Observationally: - We ALWAYS want to configure Code Manager - We ALWAYS want the private key location configured the same - We can use pe_conf_data to override anything if we need to - We don't want magic To that end, this commit simplifies the r10k private key input to require that the key content is supplied OR the path to a local file containing the key. The two parameters are different, and mutually exclusive.
1 parent ccbc9f3 commit 1d98389

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

plans/install.pp

+37-32
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,28 @@
1414
# used for tuning data etc.
1515
#
1616
plan pe_xl::install (
17+
# Large
1718
String[1] $master_host,
18-
Array[String[1]] $compiler_hosts = [ ],
19+
Array[String[1]] $compiler_hosts = [ ],
20+
Optional[String[1]] $master_replica_host = undef,
1921

22+
# Extra Large
2023
Optional[String[1]] $puppetdb_database_host = undef,
21-
Optional[String[1]] $master_replica_host = undef,
2224
Optional[String[1]] $puppetdb_database_replica_host = undef,
2325

26+
# Common Configuration
2427
String[1] $console_password,
25-
String[1] $version = '2018.1.3',
26-
Optional[String] $r10k_remote = undef,
27-
Optional[String] $r10k_private_key = undef,
28-
Array[String[1]] $dns_alt_names = [ ],
28+
String[1] $version = '2019.1.1',
29+
Array[String[1]] $dns_alt_names = [ ],
30+
Hash $pe_conf_data = { },
2931

32+
# Code Manager
33+
Optional[String] $r10k_remote = undef,
34+
Optional[String] $r10k_private_key_file = undef,
35+
Optional[Pe_xl::Pem] $r10k_private_key_content = undef,
36+
37+
# Other
3038
String[1] $stagingdir = '/tmp',
31-
Hash $pe_conf_data = {},
3239
) {
3340

3441
# Define a number of host groupings for use later in the plan
@@ -108,6 +115,21 @@
108115

109116
$dns_alt_names_csv = $dns_alt_names.reduce |$csv,$x| { "${csv},${x}" }
110117

118+
# Process user input for r10k private key (content or file) and set
119+
# appropriate value in $r10k_private_key. The value of this variable should
120+
# either be undef or else the key content to write.
121+
$r10k_private_key = [
122+
$r10k_private_key_file,
123+
$r10k_private_key_content,
124+
].pe_xl::flatten_compact.size ? {
125+
0 => undef, # no key data supplied
126+
2 => fail('Must specify either one or neither of r10k_private_key_file and r10k_private_key_content; not both'),
127+
1 => $r10k_private_key_file ? {
128+
String => file($r10k_private_key_file), # key file path supplied, read data from file
129+
undef => $r10k_private_key_content, # key content supplied directly, use as-is
130+
},
131+
}
132+
111133
# Validate that the name given for each system is both a resolvable name AND
112134
# the configured hostname.
113135
run_task('pe_xl::hostname', $all_hosts).each |$result| {
@@ -116,34 +138,15 @@
116138
}
117139
}
118140

119-
# Check if the r10k_private_key is a local file
120-
if ($r10k_private_key and find_file($r10k_private_key)) {
121-
# If the file exists then the config value should be the default path
122-
$_r10k_private_key = '/etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa'
123-
124-
# Set a flag for managing the content later
125-
$manage_private_key = true
126-
} else {
127-
# Just use the config as a config value
128-
$_r10k_private_key = $r10k_private_key
129-
$manage_private_key = false
130-
}
131-
132-
# Only auto configure code manager if we have given an r10k_remote
133-
$_code_manager_auto_configure = $r10k_remote ? {
134-
undef => undef, # If this is undef then it wont be passed
135-
default => true,
136-
}
137-
138141
# Generate all the needed pe.conf files
139142
$master_pe_conf = pe_xl::generate_pe_conf({
140143
'console_admin_password' => $console_password,
141144
'puppet_enterprise::puppet_master_host' => $master_host,
142145
'pe_install::puppet_master_dnsaltnames' => $dns_alt_names,
143146
'puppet_enterprise::profile::puppetdb::database_host' => $puppetdb_database_host,
147+
'puppet_enterprise::profile::master::code_manager_auto_configure' => true,
148+
'puppet_enterprise::profile::master::r10k_private_key' => '/etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa',
144149
'puppet_enterprise::profile::master::r10k_remote' => $r10k_remote,
145-
'puppet_enterprise::profile::master::code_manager_auto_configure' => $_code_manager_auto_configure,
146-
'puppet_enterprise::profile::master::r10k_private_key' => $_r10k_private_key,
147150
} + $pe_conf_data)
148151

149152
$puppetdb_database_pe_conf = pe_xl::generate_pe_conf({
@@ -227,11 +230,13 @@
227230
out::message("Finished: task pe_xl::pe_install on ${master_host}")
228231
}
229232
230-
if $manage_private_key {
231-
# Create the SSH private key
233+
if $r10k_private_key {
232234
run_task('pe_xl::mkdir_p_file', [$master_host, $ha_replica_target],
233-
path => $_r10k_private_key, # The configured path
234-
content => file($r10k_private_key), # The local file
235+
path => '/etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa',
236+
owner => 'pe-puppet',
237+
group => 'pe-puppet',
238+
mode => '0400',
239+
content => $r10k_private_key,
235240
)
236241
}
237242

types/pem.pp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Pe_xl::Pem = Regexp[/^-----BEGIN/]

0 commit comments

Comments
 (0)