476c8115c5
Replace deprecated dalen-puppetdbquery module with native puppetdb_query function using PQL syntax to resolve URI.escape compatibility issues. This is required to migrated to Puppet 8 (and kubernetes). Changes: - Remove dalen-puppetdbquery dependency from Puppetfile - Replace query_nodes() calls with puppetdb_query() using PQL syntax - Update 27 function calls across 18 Puppet manifests - Maintain equivalent functionality with improved compatibility Reviewed-on: #457
63 lines
1.9 KiB
Puppet
63 lines
1.9 KiB
Puppet
# manage incus clusters
|
|
class incus::cluster (
|
|
Boolean $members_lookup = false,
|
|
String $members_role = undef,
|
|
String $master = undef,
|
|
Array $servers = [],
|
|
Stdlib::Fqdn $server_fqdn = $facts['networking']['fqdn'],
|
|
Stdlib::Port $server_port = 8443,
|
|
){
|
|
|
|
# check that the master is named
|
|
unless !($master == undef) {
|
|
fail("master must be provided for ${title}")
|
|
}
|
|
|
|
# if lookup is enabled
|
|
if $members_lookup {
|
|
|
|
# check that the role is also set
|
|
unless !($members_role == undef) {
|
|
fail("members_role must be provided for ${title} when members_lookup is True")
|
|
}
|
|
|
|
# if it is, find hosts, sort them so they dont cause changes every run
|
|
$servers_array = sort(puppetdb_query(
|
|
"facts[certname] {
|
|
name = 'enc_role' and value = '${members_role}' and
|
|
certname in facts[certname] { name = 'region' and value = '${facts['region']}' }
|
|
}"
|
|
).map |$fact| { $fact['certname'] })
|
|
|
|
# else use provided array from params
|
|
}else{
|
|
$servers_array = $servers
|
|
}
|
|
|
|
# if its not an empty array. Give puppetdb a chance to be populated with data.
|
|
if length($servers_array) >= 3 {
|
|
|
|
# check if this is the master_node
|
|
if $master == $trusted['certname'] {
|
|
$master_bool = true
|
|
}else{
|
|
$master_bool = false
|
|
}
|
|
|
|
# find bootstrap status for servers
|
|
$bootstrap_array = puppetdb_query("inventory[certname, facts] { facts.enc_role = '${members_role}' }").map |$node| {
|
|
{
|
|
'fqdn' => $node['certname'],
|
|
'ip' => $node['facts']['networking']['ip'],
|
|
'clustered' => $node['facts']['incus']['environment']['server_clustered'],
|
|
'certificate' => $node['facts']['incus']['environment']['certificate'],
|
|
}
|
|
}
|
|
|
|
# determine if the cluster is bootstrapped
|
|
$cluster_bootstrapped = $bootstrap_array.any |$server| {
|
|
$server['fqdn'] == $master and $server['clustered'] == true
|
|
}
|
|
}
|
|
}
|