From 7704c0c424db04813f8ae275194979f620861329 Mon Sep 17 00:00:00 2001 From: Cody Herriges <193064+ody@users.noreply.github.com> Date: Mon, 29 Aug 2022 22:29:30 +0000 Subject: [PATCH] Re-use sync_global_hiera plan Modifies the peadm::util::sync_global_hera plan so that it can handle the copying of many files from a source to a group of targets. Renames the plan to peadm::util::copy_file --- plans/add_compiler.pp | 5 ++-- plans/add_replica.pp | 19 +++++++++++---- plans/subplans/configure.pp | 34 +++++++++++++-------------- plans/util/copy_file.pp | 26 ++++++++++++++++++++ plans/util/sync_global_hiera.pp | 22 ----------------- spec/plans/add_compiler_spec.rb | 4 ++-- spec/plans/add_replica_spec.rb | 4 ++-- spec/plans/subplans/configure_spec.rb | 2 +- 8 files changed, 65 insertions(+), 51 deletions(-) create mode 100644 plans/util/copy_file.pp delete mode 100644 plans/util/sync_global_hiera.pp diff --git a/plans/add_compiler.pp b/plans/add_compiler.pp index a4289feb..023cce62 100644 --- a/plans/add_compiler.pp +++ b/plans/add_compiler.pp @@ -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 , run the puppet agent diff --git a/plans/add_replica.pp b/plans/add_replica.pp index 001dba97..b30e581e 100644 --- a/plans/add_replica.pp +++ b/plans/add_replica.pp @@ -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, diff --git a/plans/subplans/configure.pp b/plans/subplans/configure.pp index e6d04f44..c00ac6e8 100644 --- a/plans/subplans/configure.pp +++ b/plans/subplans/configure.pp @@ -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 diff --git a/plans/util/copy_file.pp b/plans/util/copy_file.pp new file mode 100644 index 00000000..793364fb --- /dev/null +++ b/plans/util/copy_file.pp @@ -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") + } +} diff --git a/plans/util/sync_global_hiera.pp b/plans/util/sync_global_hiera.pp deleted file mode 100644 index ada8ff11..00000000 --- a/plans/util/sync_global_hiera.pp +++ /dev/null @@ -1,22 +0,0 @@ -# @api private -plan peadm::util::sync_global_hiera ( - Peadm::SingleTargetSpec $targets, - Peadm::SingleTargetSpec $primary_host, -) { - - $primary_target = peadm::get_targets($primary_host, 1) - $replica_target = $targets - - # Source the global hiera.yaml from Primary and synchronize to new Replica - $global_hiera_yaml = run_task('peadm::read_file', $primary_target, - path => '/etc/puppetlabs/puppet/hiera.yaml', - ).first['content'] - - run_task('peadm::mkdir_p_file', $replica_target, - path => '/etc/puppetlabs/puppet/hiera.yaml', - owner => 'root', - group => 'root', - mode => '0644', - content => $global_hiera_yaml, - ) -} diff --git a/spec/plans/add_compiler_spec.rb b/spec/plans/add_compiler_spec.rb index a183aad3..f28240a3 100644 --- a/spec/plans/add_compiler_spec.rb +++ b/spec/plans/add_compiler_spec.rb @@ -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 @@ -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 diff --git a/spec/plans/add_replica_spec.rb b/spec/plans/add_replica_spec.rb index a903fbfe..509ae13c 100644 --- a/spec/plans/add_replica_spec.rb +++ b/spec/plans/add_replica_spec.rb @@ -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...') @@ -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...') diff --git a/spec/plans/subplans/configure_spec.rb b/spec/plans/subplans/configure_spec.rb index be5971ec..a8b5c4bd 100644 --- a/spec/plans/subplans/configure_spec.rb +++ b/spec/plans/subplans/configure_spec.rb @@ -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