# frozen_string_literal: true require 'facter' require 'yaml' Facter.add('minio_pool_dns') do setcode do yaml_file_path = '/opt/puppetlabs/facter/facts.d/minio_facts.yaml' # check if the YAML file exists next {} unless File.exist?(yaml_file_path) # load data from YAML data = YAML.load_file(yaml_file_path) minio_members = data['minio_members'] minio_region = data['minio_region'] minio_pool = data['minio_pool'] domain = Facter.value(:networking)['domain'] # create result hash result = {} # Check CNAME for each node_id from 1 to minio_members (1..minio_members).each do |node_id| cname_target = "#{minio_region}-#{minio_pool}-#{node_id}.#{domain}" command = "host #{cname_target} > /dev/null 2>&1" # Using system method to execute the command # It returns true if the command gives exit status 0 (success), otherwise false result[cname_target] = system(command) end result end end