diff --git a/REFERENCE.md b/REFERENCE.md index b7827e8c..a7bd1d38 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1384,6 +1384,12 @@ Data type: `String` The PE Main server +##### `pe_version` + +Data type: `String` + +The PE version + ### `pe_uninstall` Uninstall Puppet Enterprise diff --git a/plans/subplans/configure.pp b/plans/subplans/configure.pp index 2afa0084..f2ebada6 100644 --- a/plans/subplans/configure.pp +++ b/plans/subplans/configure.pp @@ -124,10 +124,15 @@ } if $ldap_config { + $pe_version = run_task('peadm::read_file', $primary_target, + path => '/opt/puppetlabs/server/pe_version', + )[0][content].chomp + # Run the task to configure ldap $ldap_result = run_task('peadm::pe_ldap_config', $primary_target, pe_main => $primary_target.peadm::certname(), ldap_config => $ldap_config, + pe_version => $pe_version, '_catch_errors' => true, ) diff --git a/tasks/pe_ldap_config.json b/tasks/pe_ldap_config.json index fe388dd9..de360620 100644 --- a/tasks/pe_ldap_config.json +++ b/tasks/pe_ldap_config.json @@ -8,6 +8,10 @@ "pe_main": { "type": "String", "description": "The PE Main server" + }, + "pe_version": { + "type": "String", + "description": "The PE version" } }, "input_method": "stdin", diff --git a/tasks/pe_ldap_config.rb b/tasks/pe_ldap_config.rb index ab00dd15..70953c48 100755 --- a/tasks/pe_ldap_config.rb +++ b/tasks/pe_ldap_config.rb @@ -12,6 +12,7 @@ def main params = JSON.parse(STDIN.read) data = params['ldap_config'] pe_main = params['pe_main'] + pe_version = params['pe_version'] caf = ['/opt/puppetlabs/bin/puppet', 'config', 'print', 'localcacert'] cafout, cafstatus = Open3.capture2(*caf) @@ -31,15 +32,23 @@ def main raise 'Could not get the Key file path.' end - uri = URI("https://#{pe_main}:4433/rbac-api/v1/ds") - https = Net::HTTP.new(uri.host, uri.port) + if Gem::Version.new(pe_version) < Gem::Version.new('2023.8.0') + ldap_path = URI('rbac-api/v1/ds') + uri = URI("https://#{pe_main}:4433/#{ldap_path}") + req = Net::HTTP::Put.new(uri, 'Content-type' => 'application/json') + else + ldap_path = URI('rbac-api/v1/command/ldap/create') + uri = URI("https://#{pe_main}:4433/#{ldap_path}") + req = Net::HTTP::Post.new(uri, 'Content-type' => 'application/json') + end + + https = Net::HTTP.new(pe_main, '4433') https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_PEER https.ca_file = cafout.strip https.cert = OpenSSL::X509::Certificate.new(File.read(certout.strip)) https.key = OpenSSL::PKey::RSA.new(File.read(keyout.strip)) - req = Net::HTTP::Put.new(uri, 'Content-type' => 'application/json') req.body = data.to_json resp = https.request(req)