Skip to content

Commit 7583420

Browse files
committed
Add convert plan; replaces upgrade_trusted_facts
The convert plan serves to upgrade peadm deployments created using 0.5.x of the module, as well as to adopt manually deployed PE infrastructure for management with peadm.
1 parent 1634b7f commit 7583420

File tree

9 files changed

+206
-110
lines changed

9 files changed

+206
-110
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Plans:
1616

1717
* [Provision](documentation/provision.md)
1818
* [Upgrade](documentation/upgrade.md)
19+
* [Convert](documentation/convert.md)
1920

2021
Reference:
2122

2223
* [Classification](documentation/classification.md)
2324
* [Architectures](documentation/architectures.md)
2425
* [Testing](documentation/pre_post_checks.md)
25-
* [Converting From Old Versions of peadm](documentation/old_versions_of_peadm.md)

documentation/convert.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Convert infrastructure for use with the peadm module
2+
3+
The peadm::convert plan can be used to adopt manually deployed infrastructure for use with peadm, or to adopt infrastructure deployed with a version of peadm older than 1.0.0.
4+
5+
## Convert an Existing Deployment
6+
7+
Prepare to run the plan against all servers in the PE infrastructure, using a params.json file such as this one:
8+
9+
```json
10+
{
11+
"master_host": "pe-xl-core-0.lab1.puppet.vm",
12+
"master_replica_host": "pe-xl-core-1.lab1.puppet.vm",
13+
"compiler_hosts": [
14+
"pe-xl-compiler-0.lab1.puppet.vm",
15+
"pe-xl-compiler-1.lab1.puppet.vm"
16+
],
17+
18+
"compiler_pool_address": "puppet.lab1.puppet.vm",
19+
}
20+
```
21+
22+
See the [provision](provision.md#reference-architectures) documentation for a list of supported architectures. Note that for convert, *all infrastructure being converted must already be functional*; you cannot use convert to add new systems to the infrastructure, nor can you use it to change your architecture.
23+
24+
```
25+
bolt plan run peadm::convert --params @params.json
26+
```

documentation/old_versions_of_peadm.md

-66
This file was deleted.

manifests/setup/node_manager_yaml.pp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class peadm::setup::node_manager_yaml (
2+
String $master_host,
3+
) {
4+
5+
# Necessary to give the sandboxed Puppet executor the configuration
6+
# necessary to connect to the classifier`
7+
file { 'node_manager.yaml':
8+
ensure => file,
9+
mode => '0644',
10+
path => Deferred('peadm::node_manager_yaml_location'),
11+
content => epp('peadm/node_manager.yaml.epp', {
12+
server => $master_host,
13+
}),
14+
}
15+
16+
}

plans/action/configure.pp

+7-25
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,19 @@
5656

5757
# Set up the console node groups to configure the various hosts in their roles
5858

59-
# Pending resolution of Bolt GH-1244, Target objects and their methods are
60-
# not accessible inside apply() blocks. Work around the limitation for now
61-
# by using string variables calculated outside the apply block. The
62-
# commented-out values should be used once GH-1244 is resolved.
63-
64-
# WORKAROUND: GH-1244
65-
$master_host_string = $master_target.peadm::target_name()
66-
$master_replica_host_string = $master_replica_target.peadm::target_name()
67-
$puppetdb_database_host_string = $puppetdb_database_target.peadm::target_name()
68-
$puppetdb_database_replica_host_string = $puppetdb_database_replica_target.peadm::target_name()
69-
7059
apply($master_target) {
71-
# Necessary to give the sandboxed Puppet executor the configuration
72-
# necessary to connect to the classifier`
73-
file { 'node_manager.yaml':
74-
ensure => file,
75-
mode => '0644',
76-
path => Deferred('peadm::node_manager_yaml_location'),
77-
content => epp('peadm/node_manager.yaml.epp', {
78-
server => $master_host_string,
79-
}),
60+
class { 'peadm::setup::node_manager_yaml':
61+
master_host => $master_target.peadm::target_name(),
8062
}
8163

8264
class { 'peadm::setup::node_manager':
8365
# WORKAROUND: GH-1244
84-
master_host => $master_host_string, # $master_target.peadm::target_name(),
85-
master_replica_host => $master_replica_host_string, # $master_replica_target.peadm::target_name(),
86-
puppetdb_database_host => $puppetdb_database_host_string, # $puppetdb_database_target.peadm::target_name(),
87-
puppetdb_database_replica_host => $puppetdb_database_replica_host_string, # $puppetdb_database_replica_target.peadm::target_name(),
66+
master_host => $master_target.peadm::target_name(),
67+
master_replica_host => $master_replica_target.peadm::target_name(),
68+
puppetdb_database_host => $puppetdb_database_target.peadm::target_name(),
69+
puppetdb_database_replica_host => $puppetdb_database_replica_target.peadm::target_name(),
8870
compiler_pool_address => $compiler_pool_address,
89-
require => File['node_manager.yaml'],
71+
require => Class['peadm::setup::node_manager_yaml'],
9072
}
9173
}
9274

plans/convert.pp

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
plan peadm::convert (
2+
# Standard
3+
Peadm::SingleTargetSpec $master_host,
4+
Optional[Peadm::SingleTargetSpec] $master_replica_host = undef,
5+
6+
# Large
7+
Optional[TargetSpec] $compiler_hosts = undef,
8+
9+
# Extra Large
10+
Optional[Peadm::SingleTargetSpec] $puppetdb_database_host = undef,
11+
Optional[Peadm::SingleTargetSpec] $puppetdb_database_replica_host = undef,
12+
13+
# Common Configuration
14+
String $compiler_pool_address = $master_host,
15+
Array[String] $dns_alt_names = [ ],
16+
) {
17+
# Convert inputs into targets.
18+
$master_target = peadm::get_targets($master_host, 1)
19+
$master_replica_target = peadm::get_targets($master_replica_host, 1)
20+
$puppetdb_database_replica_target = peadm::get_targets($puppetdb_database_replica_host, 1)
21+
$compiler_targets = peadm::get_targets($compiler_hosts)
22+
$puppetdb_database_target = peadm::get_targets($puppetdb_database_host, 1)
23+
24+
$all_targets = peadm::flatten_compact([
25+
$master_target,
26+
$master_replica_target,
27+
$puppetdb_database_replica_target,
28+
$compiler_targets,
29+
$puppetdb_database_target,
30+
])
31+
32+
# Ensure input valid for a supported architecture
33+
$arch = peadm::validate_architecture(
34+
$master_host,
35+
$master_replica_host,
36+
$puppetdb_database_host,
37+
$puppetdb_database_replica_host,
38+
$compiler_hosts,
39+
)
40+
41+
# Get trusted fact information for all compilers. Use peadm::target_name() as
42+
# the hash key because the apply block below will break trying to parse the
43+
# $compiler_extensions variable if it has Target-type hash keys.
44+
$compiler_extensions = run_task('peadm::trusted_facts', $compiler_targets).reduce({}) |$memo,$result| {
45+
$memo + { $result.target.peadm::target_name() => $result['extensions'] }
46+
}
47+
48+
# Clusters A and B are used to divide PuppetDB availability for compilers. If
49+
# the compilers given already have pp_cluster facts designating them A or B,
50+
# use that. Otherwise, divide them by modulus of 2.
51+
if $arch['high-availability'] {
52+
$compiler_a_targets = $compiler_targets.filter |$index,$target| {
53+
$compiler_extensions[$target.peadm::target_name()][peadm::oid('pp_cluster')] =~ /^[AB]$/ ? {
54+
true => $compiler_extensions[$target.peadm::target_name()][peadm::oid('pp_cluster')] == 'A',
55+
false => $index % 2 == 0,
56+
}
57+
}
58+
$compiler_b_targets = $compiler_targets.filter |$index,$target| {
59+
$compiler_extensions[$target.peadm::target_name()][peadm::oid('pp_cluster')] =~ /^[AB]$/ ? {
60+
true => $compiler_extensions[$target.peadm::target_name()][peadm::oid('pp_cluster')] == 'B',
61+
false => $index % 2 != 0,
62+
}
63+
}
64+
}
65+
else {
66+
$compiler_a_targets = $compiler_targets
67+
$compiler_b_targets = []
68+
}
69+
70+
# Modify csr_attributes.yaml and insert the peadm-specific OIDs to identify
71+
# each server's role and availability group
72+
73+
run_plan('peadm::util::add_cert_extensions', $master_target,
74+
master_host => $master_target,
75+
extensions => {
76+
peadm::oid('peadm_role') => 'puppet/master',
77+
peadm::oid('peadm_availability_group') => 'A',
78+
},
79+
)
80+
81+
run_plan('peadm::util::add_cert_extensions', $master_replica_target,
82+
master_host => $master_target,
83+
extensions => {
84+
peadm::oid('peadm_role') => 'puppet/master',
85+
peadm::oid('peadm_availability_group') => 'B',
86+
},
87+
)
88+
89+
run_plan('peadm::util::add_cert_extensions', $puppetdb_database_target,
90+
master_host => $master_target,
91+
extensions => {
92+
peadm::oid('peadm_role') => 'puppet/puppetdb-database',
93+
peadm::oid('peadm_availability_group') => 'A',
94+
},
95+
)
96+
97+
run_plan('peadm::util::add_cert_extensions', $puppetdb_database_replica_target,
98+
master_host => $master_target,
99+
extensions => {
100+
peadm::oid('peadm_role') => 'puppet/puppetdb-database',
101+
peadm::oid('peadm_availability_group') => 'B',
102+
},
103+
)
104+
105+
run_plan('peadm::util::add_cert_extensions', $compiler_a_targets,
106+
master_host => $master_target,
107+
extensions => {
108+
peadm::oid('peadm_role') => 'puppet/compiler',
109+
peadm::oid('peadm_availability_group') => 'A',
110+
},
111+
)
112+
113+
run_plan('peadm::util::add_cert_extensions', $compiler_b_targets,
114+
master_host => $master_target,
115+
extensions => {
116+
peadm::oid('peadm_role') => 'puppet/compiler',
117+
peadm::oid('peadm_availability_group') => 'B',
118+
},
119+
)
120+
121+
# Create the necessary node groups in the console
122+
123+
apply($master_target) {
124+
class { 'peadm::setup::node_manager_yaml':
125+
master_host => $master_target.peadm::target_name(),
126+
}
127+
128+
class { 'peadm::setup::node_manager':
129+
master_host => $master_target.peadm::target_name(),
130+
master_replica_host => $master_replica_target.peadm::target_name(),
131+
puppetdb_database_host => $puppetdb_database_target.peadm::target_name(),
132+
puppetdb_database_replica_host => $puppetdb_database_replica_target.peadm::target_name(),
133+
compiler_pool_address => $compiler_pool_address,
134+
require => Class['peadm::setup::node_manager_yaml'],
135+
}
136+
}
137+
138+
# Run Puppet on all targets to ensure catalogs and exported resources fully
139+
# up-to-date
140+
run_task('peadm::puppet_runonce', $all_targets)
141+
142+
return("Conversion to peadm Puppet Enterprise ${arch['architecture']} succeeded.")
143+
}

plans/upgrade.pp

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@
5858
fail_plan(@(HEREDOC/L))
5959
Required trusted facts are not present; upgrade cannot be completed. If \
6060
this infrastructure was provisioned with an old version of peadm, you may \
61-
need to run the peadm::misc::upgrade_trusted_facts plan against each of the \
62-
infrastructure nodes.
61+
need to run the peadm::convert plan\
6362
| HEREDOC
6463
}
6564

plans/misc/upgrade_trusted_facts.pp plans/util/add_cert_extensions.pp

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
plan peadm::misc::upgrade_trusted_facts (
2-
TargetSpec $targets,
3-
Peadm::SingleTargetSpec $master_host,
1+
plan peadm::util::add_cert_extensions (
2+
TargetSpec $targets,
3+
TargetSpec $master_host,
4+
Hash $extensions,
45
) {
5-
6-
# Convert input into array of Targets
76
$all_targets = peadm::get_targets($targets)
87
$master_target = peadm::get_targets($master_host, 1)
98

@@ -35,15 +34,12 @@
3534
$all_targets.map |$target| {
3635

3736
# This will be the new trusted fact data for this node
38-
$new_trusted = $certdata[$target]['extensions'] + {
39-
peadm::oid('peadm_role') => $certdata[$target]['extensions'][peadm::oid('pp_application')],
40-
peadm::oid('peadm_availability_group') => $certdata[$target]['extensions'][peadm::oid('pp_cluster')],
41-
}
37+
$extension_requests = $certdata[$target]['extensions'] + $extensions
4238

4339
# Make sure the csr_attributes.yaml file on the node matches
44-
run_plan('peadm::util::insert_csr_extensions', $target,
45-
extensions => $new_trusted,
46-
merge => false,
40+
run_plan('peadm::util::insert_csr_extension_requests', $target,
41+
extension_requests => $extension_requests,
42+
merge => false,
4743
)
4844

4945
# Everything starts the same; we always revoke the existing cert

plans/util/insert_csr_extensions.pp plans/util/insert_csr_extension_requests.pp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
plan peadm::util::insert_csr_extensions (
1+
plan peadm::util::insert_csr_extension_requests (
22
TargetSpec $targets,
3-
Hash $extensions,
3+
Hash $extension_requests,
44
Boolean $merge = true,
55
) {
66
get_targets($targets).each |$target| {
@@ -15,8 +15,8 @@
1515
# If we're not merging, only ours will be used; existing requests will be
1616
# overritten.
1717
$csr_file_data = $merge ? {
18-
true => $csr_attributes_data.deep_merge({'extension_requests' => $extensions}),
19-
false => ($csr_attributes_data + {'extension_requests' => $extensions}),
18+
true => $csr_attributes_data.deep_merge({'extension_requests' => $extension_requests}),
19+
false => ($csr_attributes_data + {'extension_requests' => $extension_requests}),
2020
}
2121

2222
run_task('peadm::mkdir_p_file', $target,

0 commit comments

Comments
 (0)