Sha256: 159acf95093bb3dc0feb3b0d96980d8c30f5ed63b23f3c7bfd23a102712fa6e6
Contents?: true
Size: 1.26 KB
Versions: 15
Compression:
Stored size: 1.26 KB
Contents
# frozen_string_literal: true module Facter module Resolvers class Hostname < BaseResolver @semaphore = Mutex.new @fact_list ||= {} class << self private def post_resolve(fact_name) @fact_list.fetch(fact_name) { retrieve_hostname(fact_name) } end def retrieve_hostname(fact_name) output = Facter::Core::Execution.execute('hostname', logger: log) # get domain domain = read_domain(output) # get hostname hostname = output =~ /(.*?)\./ ? Regexp.last_match(1) : output @fact_list[:hostname] ||= hostname&.strip @fact_list[:domain] ||= domain&.strip @fact_list[:fqdn] ||= "#{@fact_list[:hostname]}.#{@fact_list[:domain]}" @fact_list[fact_name] end def read_domain(output) if output =~ /.*?\.(.+$)/ domain = Regexp.last_match(1) else file_content = Util::FileHelper.safe_read('/etc/resolv.conf') if file_content =~ /^search\s+(\S+)/ domain = Regexp.last_match(1) elsif file_content =~ /^domain\s+(\S+)/ domain = Regexp.last_match(1) end end domain end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems