diff --git a/REFERENCE.md b/REFERENCE.md index 76d618c3c..e61df4ed1 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -56,6 +56,7 @@ * [`backup_classification`](#backup_classification): A task to call the classification api and write to file * [`cert_data`](#cert_data): Return certificate data related to the Puppet agent * [`cert_valid_status`](#cert_valid_status): Check primary for valid state of a certificate +* [`classify_compilers`](#classify_compilers): Classify compilers as legacy or non-legacy * [`code_manager`](#code_manager): Perform various code manager actions * [`code_sync_status`](#code_sync_status): A task to confirm code is in sync accross the cluster for clusters with code manager configured * [`divert_code_manager`](#divert_code_manager): Divert the code manager live-dir setting @@ -1056,6 +1057,20 @@ Data type: `String` The certifcate name to check validation of +### `classify_compilers` + +Classify compilers as legacy or non-legacy + +**Supports noop?** false + +#### Parameters + +##### `compiler_hosts` + +Data type: `Array[String]` + +List of FQDNs of compilers + ### `code_manager` Perform various code manager actions diff --git a/manifests/setup/legacy_compiler_group.pp b/manifests/setup/legacy_compiler_group.pp index 5745eea9c..24041e4a1 100644 --- a/manifests/setup/legacy_compiler_group.pp +++ b/manifests/setup/legacy_compiler_group.pp @@ -32,7 +32,7 @@ ], classes => { 'puppet_enterprise::profile::master' => { - 'puppetdb_host' => [$internal_compiler_b_pool_address].filter |$_| { $_ }, + 'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_b_pool_address].filter |$_| { $_ }, 'puppetdb_port' => [8081], }, }, @@ -54,7 +54,7 @@ ], classes => { 'puppet_enterprise::profile::master' => { - 'puppetdb_host' => [$internal_compiler_b_pool_address].filter |$_| { $_ }, + 'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_a_pool_address].filter |$_| { $_ }, 'puppetdb_port' => [8081], }, }, @@ -69,4 +69,4 @@ node_group { 'PE Compiler': rule => ['and', ['=', ['trusted', 'extensions', peadm::oid('peadm_legacy_compiler')], 'false']], } -} +} \ No newline at end of file diff --git a/manifests/setup/node_manager.pp b/manifests/setup/node_manager.pp index 47acd960f..b6d5f096a 100644 --- a/manifests/setup/node_manager.pp +++ b/manifests/setup/node_manager.pp @@ -253,7 +253,7 @@ ], classes => { 'puppet_enterprise::profile::master' => { - 'puppetdb_host' => [$internal_compiler_b_pool_address].filter |$_| { $_ }, + 'puppetdb_host' => [$internal_compiler_a_pool_address].filter |$_| { $_ }, 'puppetdb_port' => [8081], }, }, diff --git a/tasks/classify_compilers.json b/tasks/classify_compilers.json new file mode 100644 index 000000000..cb85a1ddc --- /dev/null +++ b/tasks/classify_compilers.json @@ -0,0 +1,15 @@ +{ + "description": "Classify compilers as legacy or non-legacy", + "parameters": { + "compiler_hosts": { + "type": "Array[String]", + "description": "List of FQDNs of compilers" + } + }, + "implementations": [ + { + "name": "classify_compilers.rb", + "requirements": ["shell"] + } + ] +} \ No newline at end of file diff --git a/tasks/classify_compilers.rb b/tasks/classify_compilers.rb new file mode 100755 index 000000000..754f6ad9a --- /dev/null +++ b/tasks/classify_compilers.rb @@ -0,0 +1,43 @@ +#!/usr/bin/env ruby + +require 'json' +require 'open3' + +def classify_compiler(services) + if services.any? { |service| service['type'] == 'puppetdb' } + :non_legacy + else + :legacy + end +end + +params = JSON.parse(STDIN.read) +compiler_hosts = params['compiler_hosts'] + +legacy_compilers = [] +non_legacy_compilers = [] + +compiler_hosts.each do |compiler| + cmd = "puppet infra status --host #{compiler} --format=json" + stdout, stderr, status = Open3.capture3(cmd) + + if status.success? + services = JSON.parse(stdout) + classification = classify_compiler(services) + + if classification == :legacy + legacy_compilers << compiler + else + non_legacy_compilers << compiler + end + else + STDERR.puts "Error running command for #{compiler}: #{stderr}" + end +end + +result = { + 'legacy_compilers' => legacy_compilers, + 'compilers' => non_legacy_compilers +} + +puts result.to_json