4bf0d07e54
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
76 lines
2.4 KiB
Puppet
76 lines
2.4 KiB
Puppet
# profiles::proxmox::clusterjoin
|
|
class profiles::proxmox::clusterjoin {
|
|
|
|
# include params class
|
|
include profiles::proxmox::params
|
|
|
|
# localise some vars
|
|
$clusterinit_master = $profiles::proxmox::params::pve_clusterinit_master
|
|
$clustername = $profiles::proxmox::params::pve_cluster
|
|
$membersrole = $profiles::proxmox::params::pve_members_role
|
|
$root_password = $profiles::proxmox::params::root_password
|
|
|
|
# query puppetdb for list of cluster members
|
|
$members_array = sort(puppetdb_query(
|
|
"nodes[certname] {
|
|
facts.enc_role = '${membersrole}' and
|
|
facts.country = '${facts['country']}' and
|
|
facts.region = '${facts['region']}' and
|
|
facts.pve_cluster.cluster_name = '${clustername}'
|
|
}"
|
|
).map |$node| { $node['certname'] })
|
|
|
|
# check if the pve kernerl is running
|
|
if $facts['kernelrelease'] == $profiles::proxmox::params::pve_kernel_release {
|
|
|
|
# if this is the cluster master
|
|
if $clusterinit_master {
|
|
|
|
# there are no cluster members in puppetdb
|
|
if empty($members_array) {
|
|
|
|
# and this host isnt already in a cluster by itself
|
|
if ! $facts['pve_cluster'] {
|
|
|
|
# initialise a cluster
|
|
exec {'pve_init_cluster':
|
|
command => "/usr/bin/pvecm create ${clustername}",
|
|
unless => 'pvecm status',
|
|
timeout => 60,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# for non-masters
|
|
if ! $clusterinit_master {
|
|
|
|
# if there are already members of the cluster
|
|
if !empty($members_array) {
|
|
|
|
# and this host isnt already in a cluster
|
|
if ! $facts['pve_cluster'] {
|
|
|
|
# create an expect script to join the cluster
|
|
file { '/usr/local/bin/join_pvecluster.expect':
|
|
ensure => file,
|
|
owner => 'root',
|
|
mode => '0755',
|
|
content => template('profiles/proxmox/join_pvecluster.erb'),
|
|
}
|
|
|
|
exec { 'pve_join_cluster':
|
|
command => "/usr/local/bin/join_pvecluster.expect '${root_password.unwrap}' '${members_array[0]}'",
|
|
require => [File['/usr/local/bin/join_pvecluster.expect'], Package['expect']],
|
|
unless => "/usr/bin/pvesh nodes | grep -q '${facts['networking']['hostname']}'",
|
|
user => 'root',
|
|
}
|
|
}
|
|
} else {
|
|
notify { "No initialised cluster found for ${clustername}, not attempting to join":
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|