- a ci workflow for build tests - run pre-commit against all files Reviewed-on: #342
33 lines
830 B
Ruby
33 lines
830 B
Ruby
# 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
|
|
|
|
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
|
|
|
|
node_list.empty? ? nil : node_list
|
|
end
|
|
end
|