Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage license file #61

Merged
merged 2 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions functions/file_or_content.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function peadm::file_or_content(
String $param_name,
String $file,
String $content,
) {

$value = [
$file,
$content,
].peadm::flatten_compact.size ? {
0 => undef, # no key data supplied
2 => fail("Must specify either one or neither of ${param_name}_file and ${param_name}_content; not both"),
1 => $file ? {
String => file($file), # file path supplied, read data from file
undef => $content, # content supplied directly, use as-is
},
}

}
44 changes: 31 additions & 13 deletions plans/action/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
# over to the masters at /etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa
# If the file does not exist the value will simply be supplied to the masters
#
# @param license_key
# The license key to use with Puppet Enterprise. If this is a local file it
# will be copied over to the MoM at /etc/puppetlabs/license.key
# If the file does not exist the value will simply be supplied to the masters
#
# @param pe_conf_data
# Config data to plane into pe.conf when generated on all hosts, this can be
# used for tuning data etc.
Expand Down Expand Up @@ -36,6 +41,10 @@
Optional[String] $r10k_private_key_file = undef,
Optional[Peadm::Pem] $r10k_private_key_content = undef,

# License key
Optional[String] $license_key_file = undef,
Optional[String] $license_key_content = undef,

# Other
String $stagingdir = '/tmp',
) {
Expand Down Expand Up @@ -91,20 +100,13 @@

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

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

# Same for license key
$license_key = peadm::file_or_content('license_key', $license_key_file, $license_key_content)

$precheck_results = run_task('peadm::precheck', $all_targets)
$platform = $precheck_results.first['platform'] # Assume the platform of the first result correct
Expand Down Expand Up @@ -212,7 +214,10 @@
}

if $r10k_private_key {
run_task('peadm::mkdir_p_file', [$master_target, $master_replica_target],
run_task('peadm::mkdir_p_file', peadm::flatten_compact([
$master_target,
$master_replica_target,
]),
path => '/etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa',
owner => 'pe-puppet',
group => 'pe-puppet',
Expand All @@ -221,6 +226,19 @@
)
}

if $license_key {
run_task('peadm::mkdir_p_file', peadm::flatten_compact([
$master_target,
$master_replica_target,
]),
path => '/etc/puppetlabs/license.key',
owner => 'pe-puppet',
group => 'pe-puppet',
mode => '0400',
content => $license_key,
)
}

# Configure autosigning for the puppetdb database hosts 'cause they need it
$autosign_conf = $database_targets.reduce('') |$memo,$target| { "${target.name}\n${memo}" }
run_task('peadm::mkdir_p_file', $master_target,
Expand Down
9 changes: 9 additions & 0 deletions plans/provision.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
Optional[Peadm::Pem] $r10k_private_key_content = undef,
Optional[String] $deploy_environment = undef,

# License Key
Optional[String] $license_key_file = undef,
Optional[String] $license_key_content = undef,

# Other
Optional[String] $stagingdir = undef,
) {
Expand Down Expand Up @@ -54,6 +58,10 @@
r10k_private_key_file => $r10k_private_key_file,
r10k_private_key_content => $r10k_private_key_content,

# License Key
license_key_file => $license_key_file,
license_key_content => $license_key_content,

# Other
stagingdir => $stagingdir,
)
Expand Down Expand Up @@ -81,3 +89,4 @@
# Return a string banner reporting on what was done
return([$install_result, $configure_result])
}