From f1c5d386a8e8dc9ed045b6c64b61391c69210034 Mon Sep 17 00:00:00 2001 From: Neil Anderson Date: Fri, 20 Sep 2024 11:35:01 +0100 Subject: [PATCH] Changing localhost out for certnames --- REFERENCE.md | 8 -------- plans/add_replica.pp | 4 +--- tasks/backup_classification.rb | 2 +- tasks/code_manager_enabled.json | 7 +------ tasks/code_manager_enabled.rb | 18 ++++++------------ tasks/code_sync_status.rb | 2 +- tasks/puppet_infra_upgrade.rb | 8 ++------ tasks/restore_classification.rb | 2 +- 8 files changed, 13 insertions(+), 38 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 250da3cf..b649f54b 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1075,14 +1075,6 @@ Run on a PE primary node to check if Code Manager is enabled. **Supports noop?** false -#### Parameters - -##### `host` - -Data type: `String[1]` - -Hostname of the PE primary node - ### `code_sync_status` A task to confirm code is in sync accross the cluster for clusters with code manager configured diff --git a/plans/add_replica.pp b/plans/add_replica.pp index 54c85523..0806f33f 100644 --- a/plans/add_replica.pp +++ b/plans/add_replica.pp @@ -22,9 +22,7 @@ $replica_target = peadm::get_targets($replica_host, 1) $replica_postgresql_target = peadm::get_targets($replica_postgresql_host, 1) - $code_manager_enabled = run_task( - 'peadm::code_manager_enabled', $primary_target, host => $primary_target.peadm::certname() - ).first.value['code_manager_enabled'] + $code_manager_enabled = run_task('peadm::code_manager_enabled', $primary_target).first.value['code_manager_enabled'] if $code_manager_enabled == false { fail('Code Manager must be enabled to add a replica. Please refer to the docs for more information on enabling Code Manager.') diff --git a/tasks/backup_classification.rb b/tasks/backup_classification.rb index 5e1dcc6d..a98238cf 100755 --- a/tasks/backup_classification.rb +++ b/tasks/backup_classification.rb @@ -20,7 +20,7 @@ def execute! private def https_client - client = Net::HTTP.new('localhost', '4433') + client = Net::HTTP.new(Puppet.settings[:certname], 4433) client.use_ssl = true client.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert])) client.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey])) diff --git a/tasks/code_manager_enabled.json b/tasks/code_manager_enabled.json index 85d24c67..5de593b9 100644 --- a/tasks/code_manager_enabled.json +++ b/tasks/code_manager_enabled.json @@ -1,10 +1,5 @@ { "description": "Run on a PE primary node to check if Code Manager is enabled.", - "parameters": { - "host": { - "type": "String[1]", - "description": "Hostname of the PE primary node" - } - }, + "parameters": {}, "input_method": "stdin" } diff --git a/tasks/code_manager_enabled.rb b/tasks/code_manager_enabled.rb index 2a8aa5b2..57dc125f 100755 --- a/tasks/code_manager_enabled.rb +++ b/tasks/code_manager_enabled.rb @@ -6,12 +6,8 @@ require 'net/http' require 'puppet' -# GetPEAdmConfig task class -class GetPEAdmConfig - def initialize(params) - @host = params['host'] - end - +# CodeManagerEnabled task class +class CodeManagerEnabled def execute! code_manager_enabled = groups.dig('PE Master', 'classes', 'puppet_enterprise::profile::master', 'code_manager_auto_configure') @@ -20,18 +16,16 @@ def execute! puts({ 'code_manager_enabled' => code_manager_enabled_value }.to_json) end - # Returns a GetPEAdmConfig::NodeGroups object created from the /groups object - # returned by the classifier def groups @groups ||= begin - net = https(@host, 4433) + net = https res = net.get('/classifier-api/v1/groups') NodeGroup.new(JSON.parse(res.body)) end end - def https(host, port) - https = Net::HTTP.new(host, port) + def https + https = Net::HTTP.new(Puppet.settings[:certname], 4433) https.use_ssl = true https.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert])) https.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey])) @@ -68,6 +62,6 @@ def dig(name, *args) # testing of this task. unless ENV['RSPEC_UNIT_TEST_MODE'] Puppet.initialize_settings - task = GetPEAdmConfig.new(JSON.parse(STDIN.read)) + task = GetPEAdmConfig.new() task.execute! end diff --git a/tasks/code_sync_status.rb b/tasks/code_sync_status.rb index 70cd2ba1..2ad3a1f9 100755 --- a/tasks/code_sync_status.rb +++ b/tasks/code_sync_status.rb @@ -19,7 +19,7 @@ def execute! private def https_client - client = Net::HTTP.new('localhost', '8140') + client = Net::HTTP.new(Puppet.settings[:certname], 8140) client.use_ssl = true client.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert])) client.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey])) diff --git a/tasks/puppet_infra_upgrade.rb b/tasks/puppet_infra_upgrade.rb index 8a542ea5..3bc33cdc 100755 --- a/tasks/puppet_infra_upgrade.rb +++ b/tasks/puppet_infra_upgrade.rb @@ -40,17 +40,13 @@ def execute! end end - def inventory_uri - @inventory_uri ||= URI.parse('https://localhost:8143/orchestrator/v1/inventory') - end - def request_object(nodes:, token_file:) token = File.read(token_file) body = { 'nodes' => nodes, }.to_json - request = Net::HTTP::Post.new(inventory_uri.request_uri) + request = Net::HTTP::Post.new('/orchestrator/v1/inventory') request['Content-Type'] = 'application/json' request['X-Authentication'] = token.chomp request.body = body @@ -59,7 +55,7 @@ def request_object(nodes:, token_file:) end def https_object - https = Net::HTTP.new(inventory_uri.host, inventory_uri.port) + https = Net::HTTP.new(Puppet.settings[:certname], 8143) https.use_ssl = true https.cert = OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert])) https.key = OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey])) diff --git a/tasks/restore_classification.rb b/tasks/restore_classification.rb index 2761b85d..6b778b2a 100755 --- a/tasks/restore_classification.rb +++ b/tasks/restore_classification.rb @@ -20,7 +20,7 @@ def execute! private def https_client - client = Net::HTTP.new('localhost', '4433') + client = Net::HTTP.new(Puppet.settings[:certname], 4433) client.use_ssl = true client.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert])) client.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))