Skip to content

Commit fde9bbb

Browse files
committed
Merge branch 'use-new-bolt-features'
This feature merge implements newer Bolt features such as data typing based on TargetSpec, and use of Target objects by way of calling `get_targets()` and `get_target()` on user inputs. It also rolls in improvements to validation and bug fixes found along the way.
2 parents 6010b0c + 34947dc commit fde9bbb

File tree

7 files changed

+311
-218
lines changed

7 files changed

+311
-218
lines changed

functions/get_targets.pp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Accept undef or a SingleTargetSpec, and return an Array[Target, 1, 0].
2+
# This differs from get_target() in that:
3+
# - It returns an Array[Target, 1, 0], rather than a Target
4+
# - It will accept undef and return [ ].
5+
function pe_xl::get_targets(
6+
Variant[TargetSpec, Undef] $spec,
7+
Optional[Integer[1,1]] $count = undef,
8+
) {
9+
# If $spec is undef, return an empty array. Otherwise, if $count is 1, return
10+
# the result of get_target() in an array. If $count is undef, return
11+
# get_targets().
12+
$targets = $spec ? {
13+
undef => [ ],
14+
default => $count ? {
15+
1 => [get_target($spec)],
16+
undef => get_targets($spec),
17+
}
18+
}
19+
}

functions/target_host.pp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function pe_xl::target_host(
2+
Variant[Target, Array[Target,0,1]] $target,
3+
) >> Variant[String, Undef] {
4+
case $target {
5+
Target: {
6+
$target.host
7+
}
8+
Array[Target,1,1]: {
9+
$target[0].host
10+
}
11+
Array[Target,0,0]: {
12+
undef
13+
}
14+
}
15+
}

functions/validate_architecture.pp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
function pe_xl::validate_architecture (
2+
TargetSpec $master_host,
3+
Variant[TargetSpec, Undef] $master_replica_host = undef,
4+
Variant[TargetSpec, Undef] $puppetdb_database_host = undef,
5+
Variant[TargetSpec, Undef] $puppetdb_database_replica_host = undef,
6+
Variant[TargetSpec, Undef] $compiler_hosts = undef,
7+
) >> Hash {
8+
$result = case [
9+
!!($master_host),
10+
!!($master_replica_host),
11+
!!($puppetdb_database_host),
12+
!!($puppetdb_database_replica_host),
13+
] {
14+
[true, false, false, false]: { # Standard or Large, no HA
15+
({ 'high-availability' => false, 'architecture' => $compiler_hosts ? {
16+
undef => 'standard',
17+
default => 'large',
18+
}})
19+
}
20+
[true, true, false, false]: { # Standard or Large, HA
21+
({ 'high-availability' => false, 'architecture' => $compiler_hosts ? {
22+
undef => 'standard',
23+
default => 'large',
24+
}})
25+
}
26+
[true, false, true, false]: { # Extra Large, no HA
27+
({ 'high-availability' => false, 'architecture' => 'extra-large' })
28+
}
29+
[true, true, true, true]: { # Extra Large, HA
30+
({ 'high-availability' => true, 'architecture' => 'extra-large' })
31+
}
32+
default: { # Invalid
33+
out::message(inline_epp(@(HEREDOC)))
34+
Invalid architecture! Recieved:
35+
- master
36+
<% if $master_replica_host { -%>
37+
- master-replica
38+
<% } -%>
39+
<% if $puppetdb_database_host { -%>
40+
- pdb-database
41+
<% } -%>
42+
<% if $puppetdb_database_replica_host { -%>
43+
- pdb-database-replica
44+
<% } -%>
45+
<% if $compiler_hosts { -%>
46+
- compilers
47+
<% } -%>
48+
49+
Supported architectures include:
50+
Standard
51+
- master
52+
Standard with HA
53+
- master
54+
- master-replica
55+
Large
56+
- master
57+
- compilers
58+
Large with HA
59+
- master
60+
- master-replica
61+
- compilers
62+
Extra Large
63+
- master
64+
- pdb-database
65+
- compilers (optional)
66+
Extra Large with HA
67+
- master
68+
- master-replica
69+
- pdb-database
70+
- pdb-database-replica
71+
- compilers (optional)
72+
| HEREDOC
73+
74+
fail('Invalid architecture!')
75+
}
76+
}
77+
78+
# Return value
79+
$result
80+
}

plans/provision.pp

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,42 @@
33
# used by its sub-plans, and invokes them in order.
44
#
55
plan pe_xl::provision (
6-
String[1] $master_host,
7-
Optional[String[1]] $puppetdb_database_host = undef,
8-
Optional[String[1]] $master_replica_host = undef,
9-
Optional[String[1]] $puppetdb_database_replica_host = undef,
10-
Optional[Array[String[1]]] $compiler_hosts = undef,
11-
12-
String[1] $version,
13-
String[1] $console_password,
14-
Optional[Array[String[1]]] $dns_alt_names = undef,
15-
Optional[String[1]] $compiler_pool_address = undef,
16-
Optional[Hash] $pe_conf_data = undef,
17-
18-
Optional[String] $r10k_remote = undef,
19-
Optional[String] $r10k_private_key_file = undef,
20-
Optional[Pe_xl::Pem] $r10k_private_key_content = undef,
21-
Optional[String[1]] $deploy_environment = undef,
22-
23-
Optional[String[1]] $stagingdir = undef,
24-
Optional[Boolean] $executing_on_master = undef,
6+
# Standard
7+
Pe_xl::SingleTargetSpec $master_host,
8+
Optional[Pe_xl::SingleTargetSpec] $master_replica_host = undef,
9+
10+
# Large
11+
Optional[TargetSpec] $compiler_hosts = undef,
12+
13+
# Extra Large
14+
Optional[Pe_xl::SingleTargetSpec] $puppetdb_database_host = undef,
15+
Optional[Pe_xl::SingleTargetSpec] $puppetdb_database_replica_host = undef,
16+
17+
# Common Configuration
18+
String $console_password,
19+
String $version = '2019.1.1',
20+
Optional[Array[String]] $dns_alt_names = undef,
21+
Optional[String] $compiler_pool_address = undef,
22+
Optional[Hash] $pe_conf_data = { },
23+
24+
# Code Manager
25+
Optional[String] $r10k_remote = undef,
26+
Optional[String] $r10k_private_key_file = undef,
27+
Optional[Pe_xl::Pem] $r10k_private_key_content = undef,
28+
Optional[String] $deploy_environment = undef,
29+
30+
# Other
31+
Optional[String] $stagingdir = undef,
2532
) {
2633

27-
run_plan('pe_xl::unit::install',
28-
# Large
34+
$install_result = run_plan('pe_xl::unit::install',
35+
# Standard
2936
master_host => $master_host,
30-
compiler_hosts => $compiler_hosts,
3137
master_replica_host => $master_replica_host,
3238

39+
# Large
40+
compiler_hosts => $compiler_hosts,
41+
3342
# Extra Large
3443
puppetdb_database_host => $puppetdb_database_host,
3544
puppetdb_database_replica_host => $puppetdb_database_replica_host,
@@ -49,12 +58,14 @@
4958
stagingdir => $stagingdir,
5059
)
5160

52-
run_plan('pe_xl::unit::configure',
53-
# Large
61+
$configure_result = run_plan('pe_xl::unit::configure',
62+
# Standard
5463
master_host => $master_host,
55-
compiler_hosts => $compiler_hosts,
5664
master_replica_host => $master_replica_host,
5765

66+
# Large
67+
compiler_hosts => $compiler_hosts,
68+
5869
# Extra Large
5970
puppetdb_database_host => $puppetdb_database_host,
6071
puppetdb_database_replica_host => $puppetdb_database_replica_host,
@@ -65,9 +76,8 @@
6576

6677
# Other
6778
stagingdir => $stagingdir,
68-
executing_on_master => $executing_on_master,
6979
)
7080

7181
# Return a string banner reporting on what was done
72-
return('Provisioned Puppet Enterprise Extra Large cluster')
82+
return([$install_result, $configure_result])
7383
}

plans/unit/configure.pp

Lines changed: 53 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,41 @@
11
# @summary Configure first-time classification and HA setup
22
#
33
plan pe_xl::unit::configure (
4-
String[1] $master_host,
5-
Array[String[1]] $compiler_hosts = [ ],
6-
7-
Optional[String[1]] $puppetdb_database_host = undef,
8-
Optional[String[1]] $master_replica_host = undef,
9-
Optional[String[1]] $puppetdb_database_replica_host = undef,
10-
11-
# This parameter exists primarily to enable the use case of running
12-
# pe_xl::configure over the PCP transport. An orchestrator restart happens
13-
# during provision replica. Running `bolt plan run` directly on the master
14-
# and using local transport for that node will let the plan to run to
15-
# completion without failing due to being disconnected from the orchestrator.
16-
Boolean $executing_on_master = false,
17-
18-
String[1] $compiler_pool_address = $master_host,
19-
Optional[String[1]] $token_file = undef,
20-
Optional[String[1]] $deploy_environment = undef,
21-
22-
String[1] $stagingdir = '/tmp',
4+
# Large
5+
Pe_xl::SingleTargetSpec $master_host,
6+
Optional[TargetSpec] $compiler_hosts = undef,
7+
Optional[Pe_xl::SingleTargetSpec] $master_replica_host = undef,
8+
9+
# Extra Large
10+
Optional[Pe_xl::SingleTargetSpec] $puppetdb_database_host = undef,
11+
Optional[Pe_xl::SingleTargetSpec] $puppetdb_database_replica_host = undef,
12+
13+
# Common Configuration
14+
String $compiler_pool_address = $master_host,
15+
Optional[String] $token_file = undef,
16+
Optional[String] $deploy_environment = undef,
17+
18+
# Other
19+
String $stagingdir = '/tmp',
2320
) {
21+
# Convert inputs into targets.
22+
$master_target = pe_xl::get_targets($master_host, 1)
23+
$master_replica_target = pe_xl::get_targets($master_replica_host, 1)
24+
$puppetdb_database_replica_target = pe_xl::get_targets($puppetdb_database_replica_host, 1)
25+
$compiler_targets = pe_xl::get_targets($compiler_hosts)
26+
$puppetdb_database_target = $puppetdb_database_host ? {
27+
undef => $master_target,
28+
default => pe_xl::get_targets($puppetdb_database_host, 1)
29+
}
2430

25-
$ha_hosts = [
31+
# Ensure input valid for a supported architecture
32+
$arch = pe_xl::validate_architecture(
33+
$master_host,
2634
$master_replica_host,
35+
$puppetdb_database_host,
2736
$puppetdb_database_replica_host,
28-
].pe_xl::flatten_compact()
29-
30-
# Ensure valid input for HA
31-
$ha = $ha_hosts.size ? {
32-
0 => false,
33-
2 => true,
34-
default => fail('Must specify either both or neither of master_replica_host, puppetdb_database_replica_host'),
35-
}
36-
37-
# Ensure primary external database host for HA
38-
if $ha {
39-
if ! $puppetdb_database_host {
40-
fail('Must specify puppetdb_database_host for HA environment')
41-
}
42-
}
43-
44-
# Allow for the configure task to be run local to the master.
45-
$master_target = $executing_on_master ? {
46-
true => "local://${master_host}",
47-
false => $master_host,
48-
}
49-
50-
$puppetdb_database_target = $puppetdb_database_host ? {
51-
undef => $master_host,
52-
default => $puppetdb_database_host,
53-
}
37+
$compiler_hosts,
38+
)
5439

5540
# Retrieve and deploy Puppet modules from the Forge so that they can be used
5641
# for ensuring some configuration (node groups)
@@ -68,55 +53,58 @@
6853
# Set up the console node groups to configure the various hosts in their
6954
# roles
7055
run_task('pe_xl::configure_node_groups', $master_target,
71-
master_host => $master_host,
72-
master_replica_host => $master_replica_host,
73-
puppetdb_database_host => $puppetdb_database_target,
74-
puppetdb_database_replica_host => $puppetdb_database_replica_host,
56+
master_host => $master_target.pe_xl::target_host(),
57+
master_replica_host => $master_replica_target.pe_xl::target_host(),
58+
puppetdb_database_host => $puppetdb_database_target.pe_xl::target_host(),
59+
puppetdb_database_replica_host => $puppetdb_database_replica_target.pe_xl::target_host(),
7560
compiler_pool_address => $compiler_pool_address,
7661
)
7762

7863
# Run Puppet in no-op on the compilers so that their status in PuppetDB
7964
# is updated and they can be identified by the puppet_enterprise module as
8065
# CMs
81-
run_task('pe_xl::puppet_runonce', [$compiler_hosts, $master_replica_host].pe_xl::flatten_compact,
66+
run_task('pe_xl::puppet_runonce', pe_xl::flatten_compact([
67+
$compiler_targets,
68+
$master_replica_target,
69+
]),
8270
noop => true,
8371
)
8472

8573
# Run Puppet on the PuppetDB Database hosts to update their auth
8674
# configuration to allow the compilers to connect
87-
run_task('pe_xl::puppet_runonce', [
75+
run_task('pe_xl::puppet_runonce', pe_xl::flatten_compact([
8876
$puppetdb_database_target,
89-
$puppetdb_database_replica_host,
90-
].pe_xl::flatten_compact)
77+
$puppetdb_database_replica_target,
78+
]))
9179

9280
# Run Puppet on the master to ensure all services configured and
9381
# running in prep for provisioning the replica. This is done separately so
9482
# that a service restart of pe-puppetserver doesn't cause Puppet runs on
9583
# other nodes to fail.
9684
run_task('pe_xl::puppet_runonce', $master_target)
9785

98-
if $ha {
86+
if $arch['high-availability'] {
9987
# Run the PE Replica Provision
10088
run_task('pe_xl::provision_replica', $master_target,
101-
master_replica => $master_replica_host,
102-
token_file => $token_file,
89+
master_replica => $master_replica_target.pe_xl::target_host(),
90+
token_file => $token_file,
10391
)
10492

10593
# Run the PE Replica Enable
10694
run_task('pe_xl::enable_replica', $master_target,
107-
master_replica => $master_replica_host,
108-
token_file => $token_file,
95+
master_replica => $master_replica_target.pe_xl::target_host(),
96+
token_file => $token_file,
10997
)
11098
}
11199

112100
# Run Puppet everywhere to pick up last remaining config tweaks
113-
run_task('pe_xl::puppet_runonce', [
101+
run_task('pe_xl::puppet_runonce', pe_xl::flatten_compact([
114102
$master_target,
115103
$puppetdb_database_target,
116-
$compiler_hosts,
117-
$master_replica_host,
118-
$puppetdb_database_replica_host,
119-
].pe_xl::flatten_compact)
104+
$compiler_targets,
105+
$master_replica_target,
106+
$puppetdb_database_replica_target,
107+
]))
120108

121109
# Deploy an environment if a deploy environment is specified
122110
if $deploy_environment {
@@ -125,5 +113,5 @@
125113
)
126114
}
127115

128-
return('Configuration of Puppet Enterprise with replica succeeded.')
116+
return("Configuration of Puppet Enterprise ${arch['architecture']} succeeded.")
129117
}

0 commit comments

Comments
 (0)