puppet-prod/modules/incus/manifests/cluster.pp
Ben Vincent 0a978e651d feat: add incus module
- add a basic incus module
2025-03-30 01:11:50 +11:00

58 lines
1.8 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(query_nodes("enc_role='${members_role}' and region='${facts['region']}'", 'networking.fqdn'))
# 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
}
}
}