Sha256: 79f80f7a9b37c7887c2439e794d62ff57c0de425911d6b7405b876282bdeb75b

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class RedHatRelease < BaseResolver
      # :name
      # :version
      # :codename

      @fact_list ||= {}

      class << self
        private

        def post_resolve(fact_name)
          @fact_list.fetch(fact_name) { read_redhat_release(fact_name) }
        end

        def read_redhat_release(fact_name)
          output = Util::FileHelper.safe_read('/etc/redhat-release', nil)
          return @fact_list[fact_name] = nil if output.nil?

          build_fact_list(output)

          @fact_list[fact_name]
        end

        def build_fact_list(output)
          output_strings = output.split('release')
          output_strings.map!(&:strip)
          version_codename = output_strings[1].split(' ')

          @fact_list[:name] = name(output_strings[0])
          @fact_list[:version] = version_codename[0]&.strip

          codename = version_codename[1]&.strip
          @fact_list[:codename] = codename ? codename.gsub(/[()]/, '') : nil

          @fact_list[:identifier] = identifier(@fact_list[:name])
        end

        def name(name)
          name.strip.split(' ')[0..1].join
        end

        def identifier(name)
          identifier = name.strip.downcase
          identifier = 'rhel' if @fact_list[:name].strip.casecmp('Red Hat Enterprise Linux')

          identifier
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
facter-4.0.44 lib/facter/resolvers/redhat_release_resolver.rb
facter-4.0.43 lib/facter/resolvers/redhat_release_resolver.rb
facter-4.0.42 lib/facter/resolvers/redhat_release_resolver.rb
facter-4.0.41 lib/facter/resolvers/redhat_release_resolver.rb
facter-4.0.40 lib/facter/resolvers/redhat_release_resolver.rb
facter-4.0.39 lib/facter/resolvers/redhat_release_resolver.rb
facter-4.0.38 lib/facter/resolvers/redhat_release_resolver.rb
facter-4.0.37 lib/facter/resolvers/redhat_release_resolver.rb