Skip to content

Commit c3fd0a9

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 c3fd0a9

File tree

9 files changed

+204
-110
lines changed

9 files changed

+204
-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

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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
42+
$compiler_extensions = run_task('peadm::trusted_facts', $compiler_targets).reduce({}) |$memo,$result| {
43+
$memo + { $result.target => $result['extensions'] }
44+
}
45+
46+
# Clusters A and B are used to divide PuppetDB availability for compilers. If
47+
# the compilers given already have pp_cluster facts designating them A or B,
48+
# use that. Otherwise, divide them by modulus of 2.
49+
if $arch['high-availability'] {
50+
$compiler_a_targets = $compiler_targets.filter |$index,$target| {
51+
$compiler_extensions[$target][peadm::oid('pp_cluster')] =~ /^[AB]$/ ? {
52+
true => $compiler_extensions[$target][peadm::oid('pp_cluster')] == 'A',
53+
false => $index % 2 == 0,
54+
}
55+
}
56+
$compiler_b_targets = $compiler_targets.filter |$index,$target| {
57+
$compiler_extensions[$target][peadm::oid('pp_cluster')] =~ /^[AB]$/ ? {
58+
true => $compiler_extensions[$target][peadm::oid('pp_cluster')] == 'B',
59+
false => $index % 2 != 0,
60+
}
61+
}
62+
}
63+
else {
64+
$compiler_a_targets = $compiler_targets
65+
$compiler_b_targets = []
66+
}
67+
68+
# Modify csr_attributes.yaml and insert the peadm-specific OIDs to identify
69+
# each server's role and availability group
70+
71+
run_plan('peadm::util::add_cert_extensions', $master_target,
72+
master_host => $master_target,
73+
extensions => {
74+
peadm::oid('peadm_role') => 'puppet/master',
75+
peadm::oid('peadm_availability_group') => 'A',
76+
},
77+
)
78+
79+
run_plan('peadm::util::add_cert_extensions', $master_replica_target,
80+
master_host => $master_target,
81+
extensions => {
82+
peadm::oid('peadm_role') => 'puppet/master',
83+
peadm::oid('peadm_availability_group') => 'B',
84+
},
85+
)
86+
87+
run_plan('peadm::util::add_cert_extensions', $puppetdb_database_target,
88+
master_host => $master_target,
89+
extensions => {
90+
peadm::oid('peadm_role') => 'puppet/puppetdb-database',
91+
peadm::oid('peadm_availability_group') => 'A',
92+
},
93+
)
94+
95+
run_plan('peadm::util::add_cert_extensions', $puppetdb_database_replica_target,
96+
master_host => $master_target,
97+
extensions => {
98+
peadm::oid('peadm_role') => 'puppet/puppetdb-database',
99+
peadm::oid('peadm_availability_group') => 'B',
100+
},
101+
)
102+
103+
run_plan('peadm::util::add_cert_extensions', $compiler_a_targets,
104+
master_host => $master_target,
105+
extensions => {
106+
peadm::oid('peadm_role') => 'puppet/compiler',
107+
peadm::oid('peadm_availability_group') => 'A',
108+
},
109+
)
110+
111+
run_plan('peadm::util::add_cert_extensions', $compiler_b_targets,
112+
master_host => $master_target,
113+
extensions => {
114+
peadm::oid('peadm_role') => 'puppet/compiler',
115+
peadm::oid('peadm_availability_group') => 'B',
116+
},
117+
)
118+
119+
# Create the necessary node groups in the console
120+
121+
apply($master_target) {
122+
class { 'peadm::setup::node_manager_yaml':
123+
master_host => $master_target.peadm::target_name(),
124+
}
125+
126+
class { 'peadm::setup::node_manager':
127+
master_host => $master_target.peadm::target_name(),
128+
master_replica_host => $master_replica_target.peadm::target_name(),
129+
puppetdb_database_host => $puppetdb_database_target.peadm::target_name(),
130+
puppetdb_database_replica_host => $puppetdb_database_replica_target.peadm::target_name(),
131+
compiler_pool_address => $compiler_pool_address,
132+
require => Class['peadm::setup::node_manager_yaml'],
133+
}
134+
}
135+
136+
# Run Puppet on all targets to ensure catalogs and exported resources fully
137+
# up-to-date
138+
run_task('peadm::puppet_runonce', $all_targets)
139+
140+
return("Conversion to peadm Puppet Enterprise ${arch['architecture']} succeeded.")
141+
}

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)