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

support multiple puppetdb servers #409

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 17 additions & 7 deletions lib/puppet/util/puppetdb_validator.rb
Original file line number Diff line number Diff line change
@@ -24,8 +24,9 @@ def log_error(cause, code = nil)
end
end

def valid_connection_new_client?
test_uri = URI("#{use_ssl ? 'https' : 'http'}://#{puppetdb_server}:#{puppetdb_port}#{test_path}")

def valid_connection_new_client?(server)
test_uri = URI("#{use_ssl ? 'https' : 'http'}://#{server}:#{puppetdb_port}#{test_path}")
begin
conn = Puppet.runtime[:http]
_response = conn.get(test_uri, headers: test_headers)
@@ -36,14 +37,15 @@ def valid_connection_new_client?
end
end

def valid_connection_old_client?
conn = Puppet::Network::HttpPool.http_instance(puppetdb_server, puppetdb_port, use_ssl)
def valid_connection_old_client?(server)
conn = Puppet::Network::HttpPool.http_instance(server, puppetdb_port, use_ssl)
response = conn.get(test_path, test_headers)
unless response.is_a?(Net::HTTPSuccess)
log_error(response.msg, response.code)
return false
end
true

end

# Utility method; attempts to make an http/https connection to the puppetdb server.
@@ -56,11 +58,19 @@ def attempt_connection
# http(s), so here we're simpling hitting a somewhat arbitrary low-impact URL
# on the puppetdb server.

if Gem::Version.new(Puppet.version) >= Gem::Version.new('7.0.0')
valid_connection_new_client?
if Gem::Version.new(Puppet.version) >= Gem::Version.new('7.0.0')
if puppetdb_server.kind_of?(Array)
puppetdb_server.each { | server | valid_connection_new_client?(server) }
else
valid_connection_old_client?
valid_connection_new_client?(puppetdb_server)
end
else
if puppetdb_server.kind_of?(Array)
puppetdb_server.each { | server | valid_connection_old_client?(server) }
else
valid_connection_old_client?(puppetdb_server)
end
end
rescue StandardError => e
log_error(e.message)
false
24 changes: 12 additions & 12 deletions manifests/database/ssl_configuration.pp
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
$database_username = $puppetdb::params::database_username,
$read_database_username = $puppetdb::params::read_database_username,
$read_database_host = $puppetdb::params::read_database_host,
$puppetdb_server = $puppetdb::params::puppetdb_server,
Variant[String,Array[String, 1]] $puppetdb_server = $puppetdb::params::puppetdb_server,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the least we should do. would even be better to enforce IP/FQDN, but I don't know out of my head what kind of values are allowed here.

Suggested change
Variant[String,Array[String, 1]] $puppetdb_server = $puppetdb::params::puppetdb_server,
Variant[String[1],Array[String[1], 1]] $puppetdb_server = $puppetdb::params::puppetdb_server,

$postgresql_ssl_key_path = $puppetdb::params::postgresql_ssl_key_path,
$postgresql_ssl_cert_path = $puppetdb::params::postgresql_ssl_cert_path,
$postgresql_ssl_ca_cert_path = $puppetdb::params::postgresql_ssl_ca_cert_path,
@@ -54,19 +54,19 @@
require => [File['postgres private key'], File['postgres public key']],
}

puppetdb::database::postgresql_ssl_rules { "Configure postgresql ssl rules for ${database_username}":
database_name => $database_name,
database_username => $database_username,
postgres_version => $postgres_version,
puppetdb_server => $puppetdb_server,
}

if $create_read_user_rule {
puppetdb::database::postgresql_ssl_rules { "Configure postgresql ssl rules for ${read_database_username}":
flatten($puppetdb_server).each | $server | {
puppetdb::database::postgresql_ssl_rules { "Configure postgresql ssl rules for ${database_username} from ${server}":
database_name => $database_name,
database_username => $read_database_username,
database_username => $database_username,
postgres_version => $postgres_version,
puppetdb_server => $puppetdb_server,
puppetdb_server => $server,
}
if $create_read_user_rule {
puppetdb::database::postgresql_ssl_rules { "Configure postgresql ssl rules for ${read_database_username} from ${server}":
database_name => $database_name,
database_username => $read_database_username,
puppetdb_server => $server,
}
}
}
}
4 changes: 2 additions & 2 deletions manifests/master/config.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# @summary manage the puppet configuration on the primary
#
# @param puppetdb_server
# The dns name or ip of the PuppetDB server. Defaults to the hostname of the
# current node, i.e. `$::fqdn`.
# The dns name or ip of the PuppetDB server, or an Array of the same.
# Defaults to the hostname of the current node, i.e. `$::fqdn`.
#
# @param puppetdb_port
# The port that the PuppetDB server is running on. Defaults to `8081`.
8 changes: 7 additions & 1 deletion manifests/master/puppetdb_conf.pp
Original file line number Diff line number Diff line change
@@ -30,9 +30,15 @@
value => $port,
}
} else {
if is_array($server) {
$servers_url_string = $server.map | $value | { "https://${value}:${port}"}.join(',') }
} else {
$servers_url_string = "https://${server}:${port}/"
}

ini_setting { 'puppetdbserver_urls':
setting => 'server_urls',
value => "https://${server}:${port}/",
value => $servers_url_string,
}
}