ae256b7c0b
ci/woodpecker/pr/erb-validate Pipeline was successful
ci/woodpecker/pr/ruby-validate Pipeline was successful
ci/woodpecker/pr/puppet-lint Pipeline was successful
ci/woodpecker/pr/yamllint Pipeline was successful
ci/woodpecker/pr/bolt-validate Pipeline was successful
ci/woodpecker/pr/epp-validate Pipeline was successful
ci/woodpecker/pr/puppet-validate Pipeline was successful
ci/woodpecker/pr/ruby-check Pipeline was successful
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.5 KiB
Puppet
76 lines
2.5 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(
|
|
"facts[certname] {
|
|
name = 'enc_role' and value = '${membersrole}' and
|
|
certname in facts[certname] { name = 'country' and value = '${facts['country']}' } and
|
|
certname in facts[certname] { name = 'region' and value = '${facts['region']}' } and
|
|
certname in facts[certname] { name = 'pve_cluster' and value.cluster_name = '${clustername}' }
|
|
}"
|
|
).map |$fact| { $fact['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":
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|