Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use sync_global_hiera plan #281

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plans/add_compiler.pp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@
)

# Source the global hiera.yaml from Primary and synchronize to new compiler
run_plan('peadm::util::sync_global_hiera', $compiler_target,
primary_host => $primary_target
run_plan('peadm::util::copy_file', $compiler_target,
source_host => $primary_target,
path => '/etc/puppetlabs/puppet/hiera.yaml'
)

# On <compiler-host>, run the puppet agent
Expand Down
19 changes: 14 additions & 5 deletions plans/add_replica.pp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,20 @@
peadm_config => $peadm_config
)

# Source the global hiera.yaml from Primary and synchronize to new Replica
# Provision the new system as a replica
run_plan('peadm::util::sync_global_hiera', $replica_target,
primary_host => $primary_target
)
# Source list of files on Primary and synchronize to new Replica
$content_sources = [
'/opt/puppetlabs/server/data/console-services/certs/ad_ca_chain.pem',
'/etc/puppetlabs/orchestration-services/conf.d/secrets/keys.json',
'/etc/puppetlabs/orchestration-services/conf.d/secrets/orchestrator-encryption-keys.json',
'/etc/puppetlabs/console-services/conf.d/secrets/keys.json',
'/etc/puppetlabs/puppet/hiera.yaml'
]
parallelize($content_sources) |$path| {
run_plan('peadm::util::copy_file', $replica_target,
source_host => $primary_target,
path => $path
)
}

# Provision the new system as a replica
run_task('peadm::provision_replica', $primary_target,
Expand Down
34 changes: 17 additions & 17 deletions plans/subplans/configure.pp
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@
$compiler_hosts,
)

# Define the global hiera.yaml file on the Master; and syncronize to any Replica and Compilers.
# This enables Data in the Classifier/Console, which is used/required by this architecture.
# Necessary, for example, when promoting the Replica due to PE-18400 (and others).
$global_hiera_yaml = run_task('peadm::read_file', $primary_target,
path => '/etc/puppetlabs/puppet/hiera.yaml',
).first['content']

run_task('peadm::mkdir_p_file', peadm::flatten_compact([
$replica_target,
$compiler_targets,
]),
path => '/etc/puppetlabs/puppet/hiera.yaml',
owner => 'root',
group => 'root',
mode => '0644',
content => $global_hiera_yaml,
)
# Source list of files on Primary and synchronize to new Replica
$content_sources = [
'/opt/puppetlabs/server/data/console-services/certs/ad_ca_chain.pem',
'/etc/puppetlabs/orchestration-services/conf.d/secrets/keys.json',
'/etc/puppetlabs/orchestration-services/conf.d/secrets/orchestrator-encryption-keys.json',
'/etc/puppetlabs/console-services/conf.d/secrets/keys.json',
'/etc/puppetlabs/puppet/hiera.yaml'
]
parallelize($content_sources) |$path| {
run_plan('peadm::util::copy_file', peadm::flatten_compact([
$replica_target,
$compiler_targets,
]),
source_host => $primary_target,
path => $path
)
}

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

Expand Down
26 changes: 26 additions & 0 deletions plans/util/copy_file.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# @api private
plan peadm::util::copy_file(
TargetSpec $targets,
Peadm::SingleTargetSpec $source_host,
Stdlib::Absolutepath $path
) {

$source_target = peadm::get_targets($source_host, 1)
$replica_target = $targets

$source_content = run_task('peadm::read_file', $source_target,
path => $path
).first['content']

if $source_content {
run_task('peadm::mkdir_p_file', $replica_target,
path => $path,
owner => 'root',
group => 'root',
mode => '0644',
content => $source_content,
)
} else {
out::message("Skipping file copy: ${path} on ${source_target.peadm::certname()} had no content")
}
}
22 changes: 0 additions & 22 deletions plans/util/sync_global_hiera.pp

This file was deleted.

4 changes: 2 additions & 2 deletions spec/plans/add_compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def allow_standard_non_returning_calls
# ["--puppet-service-ensure", "stopped",
# "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"}

expect_plan('peadm::util::sync_global_hiera').be_called_times(1)
expect_plan('peadm::util::copy_file').be_called_times(1)
expect(run_plan('peadm::add_compiler', params)).to be_ok
end

Expand All @@ -69,7 +69,7 @@ def allow_standard_non_returning_calls
'--puppet-service-ensure', 'stopped',
'main:certname=compiler'
] })
expect_plan('peadm::util::sync_global_hiera').be_called_times(1)
expect_plan('peadm::util::copy_file').be_called_times(1)
expect(run_plan('peadm::add_compiler', params2)).to be_ok
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/plans/add_replica_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def allow_standard_non_returning_calls
'--puppet-service-ensure', 'stopped',
'main:certname=replica'
] })
expect_plan('peadm::util::sync_global_hiera')
expect_plan('peadm::util::copy_file').be_called_times(5)

expect_out_verbose.with_params('Current config is...')
expect_out_verbose.with_params('Updating classification to...')
Expand All @@ -60,7 +60,7 @@ def allow_standard_non_returning_calls
'--puppet-service-ensure', 'stopped',
'main:certname=replica'
] })
expect_plan('peadm::util::sync_global_hiera')
expect_plan('peadm::util::copy_file').be_called_times(5)

expect_out_verbose.with_params('Current config is...')
expect_out_verbose.with_params('Updating classification to...')
Expand Down
2 changes: 1 addition & 1 deletion spec/plans/subplans/configure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
allow_any_plan
allow_any_command

expect_task('peadm::read_file').always_return({ 'content' => 'mock' })
expect_task('peadm::util::copy_file').not_be_called
expect_task('peadm::provision_replica').not_be_called
expect_task('peadm::code_manager').not_be_called

Expand Down