Skip to content

Commit ac05eb1

Browse files
authoredJun 21, 2022
Merge pull request #270 from ody/add_compiler_run_puppet
Set additional rules on replica when adding compiler
2 parents 33317df + f5ae8a8 commit ac05eb1

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed
 

Diff for: ‎plans/add_compiler.pp

+34-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,35 @@
1414
Peadm::SingleTargetSpec $compiler_host,
1515
Peadm::SingleTargetSpec $primary_host,
1616
Peadm::SingleTargetSpec $primary_postgresql_host,
17-
){
17+
) {
1818
$compiler_target = peadm::get_targets($compiler_host, 1)
1919
$primary_target = peadm::get_targets($primary_host, 1)
2020
$primary_postgresql_target = peadm::get_targets($primary_postgresql_host, 1)
2121

22+
# Get current peadm config to determine where to setup additional rules for
23+
# compiler's secondary PuppetDB instances
24+
$peadm_config = run_task('peadm::get_peadm_config', $primary_target).first.value
25+
26+
# Return the opposite server than the compiler to be added so it can be
27+
# configured with the appropriate rules for Puppet Server access from
28+
# compiler
29+
$replica_avail_group_letter = $avail_group_letter ? { 'A' => 'B', 'B' => 'A' }
30+
$replica_puppetdb = $peadm_config['role-letter']['server'][$replica_avail_group_letter]
31+
32+
$replica_puppetdb_target = peadm::get_targets($replica_puppetdb, 1)
33+
2234
# Stop puppet.service
23-
run_command('systemctl stop puppet.service', $primary_postgresql_target)
35+
run_command('systemctl stop puppet.service', peadm::flatten_compact([
36+
$primary_postgresql_target,
37+
$replica_puppetdb_target
38+
]))
39+
40+
apply($replica_puppetdb_target) {
41+
file_line { 'pe-puppetdb-compiler-cert-allow':
42+
path => '/etc/puppetlabs/puppetdb/certificate-allowlist',
43+
line => $compiler_target.peadm::certname(),
44+
}
45+
}
2446

2547
# Add the following two lines to /opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf
2648
#
@@ -85,15 +107,24 @@
85107
},
86108
)
87109

110+
# Source the global hiera.yaml from Primary and synchronize to new compiler
111+
run_plan('peadm::util::sync_global_hiera', $compiler_target,
112+
primary_host => $primary_target
113+
)
114+
88115
# On <compiler-host>, run the puppet agent
89116
run_task('peadm::puppet_runonce', $compiler_target)
90117

91118
# On <primary_postgresql_host> run the puppet agent
92-
run_task('peadm::puppet_runonce', $primary_postgresql_target)
119+
run_task('peadm::puppet_runonce', peadm::flatten_compact([
120+
$primary_postgresql_target,
121+
$replica_puppetdb_target
122+
]))
93123

94124
# On <primary_postgresql_host> start puppet.service
95125
run_command('systemctl start puppet.service', peadm::flatten_compact([
96126
$primary_postgresql_target,
127+
$replica_puppetdb_target,
97128
$compiler_target,
98129
]))
99130

Diff for: ‎spec/plans/add_compiler_spec.rb

+17-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,24 @@ def allow_standard_non_returning_calls
1919
}
2020
end
2121

22+
let(:cfg) do
23+
{
24+
'params' => {
25+
'primary_host' => 'primary'
26+
},
27+
'role-letter' => {
28+
'server' => {
29+
'A' => 'server_a',
30+
'B' => 'server_b'
31+
}
32+
}
33+
}
34+
end
2235
let(:certdata) { { 'certname' => 'primary', 'extensions' => { '1.3.6.1.4.1.34380.1.1.9813' => 'A' } } }
2336

2437
it 'runs successfully when no alt-names are specified' do
2538
allow_standard_non_returning_calls
39+
expect_task('peadm::get_peadm_config').always_return(cfg)
2640
expect_plan('peadm::modify_certificate').always_return('mock' => 'mock')
2741
expect_task('peadm::agent_install')
2842
.with_params({ 'server' => 'primary',
@@ -35,6 +49,7 @@ def allow_standard_non_returning_calls
3549
# ["--puppet-service-ensure", "stopped",
3650
# "extension_requests:1.3.6.1.4.1.34380.1.3.13=pe_compiler", "extension_requests:1.3.6.1.4.1.34380.1.1.9813=A", "main:certname=compiler"], "server"=>"primary"}
3751

52+
expect_plan('peadm::util::sync_global_hiera').be_called_times(1)
3853
expect(run_plan('peadm::add_compiler', params)).to be_ok
3954
end
4055

@@ -45,6 +60,7 @@ def allow_standard_non_returning_calls
4560

4661
it 'runs successfully when alt-names are specified' do
4762
allow_standard_non_returning_calls
63+
expect_task('peadm::get_peadm_config').always_return(cfg)
4864
expect_plan('peadm::modify_certificate').always_return('mock' => 'mock')
4965
expect_task('peadm::agent_install')
5066
.with_params({ 'server' => 'primary',
@@ -53,7 +69,7 @@ def allow_standard_non_returning_calls
5369
'--puppet-service-ensure', 'stopped',
5470
'main:certname=compiler'
5571
] })
56-
72+
expect_plan('peadm::util::sync_global_hiera').be_called_times(1)
5773
expect(run_plan('peadm::add_compiler', params2)).to be_ok
5874
end
5975
end

0 commit comments

Comments
 (0)
Please sign in to comment.