feat: manage proxmox nodes

- change /etc/hosts to meet proxmox requirements
- add proxmox node role
- add init, params, repo, install, clusterjoin classes
This commit is contained in:
2024-04-17 18:23:33 +10:00
parent 7ccbb7d0ee
commit f04c74bd4d
33 changed files with 564 additions and 7 deletions
+10
View File
@@ -0,0 +1,10 @@
# frozen_string_literal: true
require 'facter'
Facter.add('is_pveceph_mgr') do
confine enc_role: 'roles::infra::proxmox::node'
setcode do
system('pgrep -x ceph-mgr > /dev/null 2>&1')
end
end
+10
View File
@@ -0,0 +1,10 @@
# frozen_string_literal: true
require 'facter'
Facter.add('is_pveceph_mon') do
confine enc_role: 'roles::infra::proxmox::node'
setcode do
system('pgrep -x ceph-mon > /dev/null 2>&1')
end
end
@@ -0,0 +1,34 @@
# frozen_string_literal: true
require 'facter'
Facter.add('ceph_global_config') do
confine enc_role: 'roles::infra::proxmox::node'
setcode do
config_file = '/etc/pve/ceph.conf'
config_hash = {}
in_global_section = false
if File.exist?(config_file)
File.readlines(config_file).each do |line|
line.strip!
# Detect the [global] section and set flag
if line == '[global]'
in_global_section = true
next
end
# Exit the loop once we're out of the global section
break if line.start_with?('[') && in_global_section
# Parse key-value pairs if we are in the global section
if in_global_section && line.include?('=')
key, value = line.split('=', 2).map(&:strip)
config_hash[key] = value
end
end
end
config_hash
end
end
@@ -0,0 +1,10 @@
# frozen_string_literal: true
require 'facter'
Facter.add('pve_ceph_initialised') do
confine enc_role: 'roles::infra::proxmox::node'
setcode do
File.exist?('/etc/pve/ceph.conf')
end
end
+28
View File
@@ -0,0 +1,28 @@
# frozen_string_literal: true
require 'facter'
Facter.add('pve_cluster') do
confine enc_role: 'roles::infra::proxmox::node'
setcode do
conf_file = '/etc/pve/corosync.conf'
totem_details = {}
in_totem_section = false
if File.exist?(conf_file)
File.foreach(conf_file) do |line|
if line =~ /^\s*totem\s*\{/
in_totem_section = true
elsif line =~ /^\s*\}/ && in_totem_section
break
elsif in_totem_section && line =~ /^\s*(\w+):\s*(.+)$/
key = Regexp.last_match(1).strip
value = Regexp.last_match(2).strip
totem_details[key] = value
end
end
end
totem_details.empty? ? nil : totem_details
end
end
@@ -0,0 +1,21 @@
# frozen_string_literal: true
require 'facter'
Facter.add('pve_cluster_member') do
confine enc_role: 'roles::infra::proxmox::node'
setcode do
if Facter::Util::Resolution.which('pvesh')
cluster_status = `pvesh get /cluster/status --output-format json`
if cluster_status.empty?
false
else
require 'json'
status = JSON.parse(cluster_status)
!status.empty?
end
else
false
end
end
end
+35
View File
@@ -0,0 +1,35 @@
# frozen_string_literal: true
require 'facter'
Facter.add('pve_nodelist') do
confine enc_role: 'roles::infra::proxmox::node'
setcode do
conf_file = '/etc/pve/corosync.conf'
node_list = {}
current_node = nil
# rubocop:disable Metrics/BlockNesting
if File.exist?(conf_file)
File.foreach(conf_file) do |line|
if line =~ /^\s*node\s*\{/
current_node = {}
elsif line =~ /^\s*\}/
if current_node
node_name = current_node['name']
node_list[node_name] = current_node if node_name
current_node = nil
end
elsif current_node && line =~ /^\s*(\w+):\s*(.+)$/
key = Regexp.last_match(1).strip
value = Regexp.last_match(2).strip
current_node[key] = value
end
end
end
# rubocop:enable Metrics/BlockNesting
node_list.empty? ? nil : node_list
end
end
@@ -0,0 +1,17 @@
# frozen_string_literal: true
require 'facter'
Facter.add('pve_nodes_active') do
confine enc_role: 'roles::infra::proxmox::node'
setcode do
if Facter::Util::Resolution.which('pvesh')
proxmox_nodes = `pvesh get /nodes --output-format json`
unless proxmox_nodes.empty?
require 'json'
nodes = JSON.parse(proxmox_nodes)
nodes.count
end
end
end
end