Skip to content

Commit bcbd7b9

Browse files
authored
Merge pull request #25 from dylanratcliffe/code_manager
Added ability fo fully bootstrap Code manager
2 parents 8ebef13 + 15bb1e6 commit bcbd7b9

File tree

7 files changed

+147
-130
lines changed

7 files changed

+147
-130
lines changed

functions/generate_pe_conf.pp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Generates a pe.conf file, removing undef parameters
2+
#
3+
# @param user_settings
4+
# A hash of settings to set in the config file. Any keys that are set to
5+
# undef will not be included in the config file. This is done to reduce the
6+
# amount of logic required within plans if parameters are not passed in.
7+
#
8+
function pe_xl::generate_pe_conf (
9+
Hash $settings,
10+
) {
11+
# Check that console_admin_password is present
12+
unless $settings['console_admin_password'] =~ String {
13+
fail('pe.conf must have the console_admin_password set')
14+
}
15+
16+
# Define the configuration settings that will be placed in pe.conf by
17+
# default. These can be overriden by user-supplied values in the $settings
18+
# hash.
19+
$defaults = {
20+
'puppet_enterprise::profile::master::java_args' => {
21+
'Xmx' => '2048m',
22+
'Xms' => '512m',
23+
},
24+
'puppet_enterprise::profile::console::java_args' => {
25+
'Xmx' => '768m',
26+
'Xms' => '256m',
27+
},
28+
'puppet_enterprise::profile::orchestrator::java_args' => {
29+
'Xmx' => '768m',
30+
'Xms' => '256m',
31+
},
32+
'puppet_enterprise::profile::puppetdb::java_args' => {
33+
'Xmx' => '768m',
34+
'Xms' => '256m',
35+
},
36+
}
37+
38+
# Merge the defaults with user-supplied settings, remove anything that is
39+
# undef, then output to JSON (and therefore HOCON, because HOCON is a
40+
# superset of JSON)
41+
($defaults + $settings).filter |$key,$value| {
42+
$value != undef
43+
}.to_json_pretty()
44+
}

lib/puppet/functions/pe_xl/to_json.rb

-11
This file was deleted.

plans/init.pp

+27-13
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,51 @@
99
Boolean $configure = false,
1010
Boolean $upgrade = false,
1111

12-
Optional[String[1]] $master_host = undef,
13-
Optional[String[1]] $puppetdb_database_host = undef,
14-
Optional[String[1]] $master_replica_host = undef,
12+
Optional[String[1]] $master_host = undef,
13+
Optional[String[1]] $puppetdb_database_host = undef,
14+
Optional[String[1]] $master_replica_host = undef,
1515
Optional[String[1]] $puppetdb_database_replica_host = undef,
16-
Optional[Array[String[1]]] $compiler_hosts = undef,
16+
Optional[Array[String[1]]] $compiler_hosts = undef,
1717

18-
Optional[String[1]] $console_password = undef,
19-
Optional[String[1]] $version = undef,
20-
Optional[Hash] $r10k_sources = undef,
21-
Optional[Array[String[1]]] $dns_alt_names = undef,
18+
Optional[String[1]] $console_password = undef,
19+
Optional[String[1]] $version = undef,
20+
Optional[Array[String[1]]] $dns_alt_names = undef,
2221
Optional[Boolean] $executing_on_master = undef,
2322

23+
Optional[String] $r10k_remote = undef,
24+
Optional[String] $r10k_private_key_file = undef,
25+
Optional[Pe_xl::Pem] $r10k_private_key_content = undef,
26+
2427
Optional[String[1]] $compiler_pool_address = undef,
25-
Optional[String[1]] $deploy_environment = undef,
28+
Optional[String[1]] $deploy_environment = undef,
2629

27-
Optional[String[1]] $stagingdir = undef,
30+
Optional[String[1]] $stagingdir = undef,
31+
Optional[Hash] $pe_conf_data = undef
2832
) {
2933

3034
if $install {
3135
run_plan('pe_xl::install',
36+
# Large
3237
master_host => $master_host,
33-
puppetdb_database_host => $puppetdb_database_host,
38+
compiler_hosts => $compiler_hosts,
3439
master_replica_host => $master_replica_host,
40+
41+
# Extra Large
42+
puppetdb_database_host => $puppetdb_database_host,
3543
puppetdb_database_replica_host => $puppetdb_database_replica_host,
36-
compiler_hosts => $compiler_hosts,
3744

45+
# Common Configuration
3846
console_password => $console_password,
3947
version => $version,
40-
r10k_sources => $r10k_sources,
4148
dns_alt_names => $dns_alt_names,
49+
pe_conf_data => $pe_conf_data,
50+
51+
# Code Manager
52+
r10k_remote => $r10k_remote,
53+
r10k_private_key_file => $r10k_private_key_file,
54+
r10k_private_key_content => $r10k_private_key_content,
4255

56+
# Other
4357
stagingdir => $stagingdir,
4458
)
4559
}

plans/install.pp

+75-24
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
11
# @summary Perform initial installation of Puppet Enterprise Extra Large
22
#
3+
# @param r10k_remote
4+
# The clone URL of the controlrepo to use. This just uses the basic config
5+
# from the documentaion https://puppet.com/docs/pe/2019.0/code_mgr_config.html
6+
#
7+
# @param r10k_private_key
8+
# The private key to use for r10k. If this is a local file it will be copied
9+
# over to the masters at /etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa
10+
# If the file does not exist the value will simply be supplied to the masters
11+
#
12+
# @param pe_conf_data
13+
# Config data to plane into pe.conf when generated on all hosts, this can be
14+
# used for tuning data etc.
15+
#
316
plan pe_xl::install (
17+
# Large
418
String[1] $master_host,
5-
Array[String[1]] $compiler_hosts = [ ],
6-
7-
Optional[String[1]] $puppetdb_database_host = undef,
19+
Array[String[1]] $compiler_hosts = [ ],
820
Optional[String[1]] $master_replica_host = undef,
21+
22+
# Extra Large
23+
Optional[String[1]] $puppetdb_database_host = undef,
924
Optional[String[1]] $puppetdb_database_replica_host = undef,
1025

26+
# Common Configuration
1127
String[1] $console_password,
12-
String[1] $version = '2018.1.3',
13-
Hash $r10k_sources = { },
28+
String[1] $version = '2019.1.1',
1429
Array[String[1]] $dns_alt_names = [ ],
30+
Hash $pe_conf_data = { },
31+
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,
1536

16-
String[1] $stagingdir = '/tmp',
37+
# Other
38+
String[1] $stagingdir = '/tmp',
1739
) {
1840

1941
# Define a number of host groupings for use later in the plan
@@ -93,6 +115,21 @@
93115

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

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+
96133
# Validate that the name given for each system is both a resolvable name AND
97134
# the configured hostname.
98135
run_task('pe_xl::hostname', $all_hosts).each |$result| {
@@ -102,23 +139,27 @@
102139
}
103140

104141
# Generate all the needed pe.conf files
105-
$master_pe_conf = epp('pe_xl/master-pe.conf.epp',
106-
console_password => $console_password,
107-
master_host => $master_host,
108-
puppetdb_database_host => $puppetdb_database_host,
109-
dns_alt_names => $dns_alt_names,
110-
r10k_sources => $r10k_sources,
111-
)
112-
113-
$puppetdb_database_pe_conf = epp('pe_xl/puppetdb_database-pe.conf.epp',
114-
master_host => $master_host,
115-
puppetdb_database_host => $puppetdb_database_host,
116-
)
117-
118-
$puppetdb_database_replica_pe_conf = epp('pe_xl/puppetdb_database-pe.conf.epp',
119-
master_host => $master_host,
120-
puppetdb_database_host => $puppetdb_database_replica_host,
121-
)
142+
$master_pe_conf = pe_xl::generate_pe_conf({
143+
'console_admin_password' => $console_password,
144+
'puppet_enterprise::puppet_master_host' => $master_host,
145+
'pe_install::puppet_master_dnsaltnames' => $dns_alt_names,
146+
'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',
149+
'puppet_enterprise::profile::master::r10k_remote' => $r10k_remote,
150+
} + $pe_conf_data)
151+
152+
$puppetdb_database_pe_conf = pe_xl::generate_pe_conf({
153+
'console_admin_password' => 'not used',
154+
'puppet_enterprise::puppet_master_host' => $master_host,
155+
'puppet_enterprise::database_host' => $puppetdb_database_host,
156+
} + $pe_conf_data)
157+
158+
$puppetdb_database_replica_pe_conf = pe_xl::generate_pe_conf({
159+
'console_admin_password' => 'not used',
160+
'puppet_enterprise::puppet_master_host' => $master_host,
161+
'puppet_enterprise::database_host' => $puppetdb_database_replica_host,
162+
} + $pe_conf_data)
122163

123164
# Upload the pe.conf files to the hosts that need them
124165
pe_xl::file_content_upload($master_pe_conf, '/tmp/pe.conf', $master_host)
@@ -189,14 +230,24 @@
189230
out::message("Finished: task pe_xl::pe_install on ${master_host}")
190231
}
191232
233+
if $r10k_private_key {
234+
run_task('pe_xl::mkdir_p_file', [$master_host, $ha_replica_target],
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,
240+
)
241+
}
242+
192243
# Configure autosigning for the puppetdb database hosts 'cause they need it
193244
$autosign_conf = $database_hosts.reduce |$memo,$host| { "${host}\n${memo}" }
194245
run_task('pe_xl::mkdir_p_file', $master_host,
195246
path => '/etc/puppetlabs/puppet/autosign.conf',
196247
owner => 'pe-puppet',
197248
group => 'pe-puppet',
198249
mode => '0644',
199-
content => "$autosign_conf",
250+
content => $autosign_conf,
200251
)
201252
202253
# Run the PE installer on the puppetdb database hosts

templates/master-pe.conf.epp

-58
This file was deleted.

templates/puppetdb_database-pe.conf.epp

-24
This file was deleted.

types/pem.pp

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

0 commit comments

Comments
 (0)