Sha256: 49e394fca09bd91860f95ce170371e67a5fdc7799856ce52944058b6b2a980f4

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class LsbRelease < BaseResolver
      # :lsb_version
      # :distributor_id
      # :description
      # :release
      # :codename

      init_resolver

      class << self
        private

        def post_resolve(fact_name, _options)
          @fact_list.fetch(fact_name) { retrieve_facts(fact_name) }
        end

        def retrieve_facts(fact_name)
          lsb_release_installed? if @fact_list[:lsb_release_installed].nil?
          read_lsb_release_file if @fact_list[:lsb_release_installed]
          @fact_list[fact_name]
        end

        def lsb_release_installed?
          @fact_list[:lsb_release_installed] = !Facter::Core::Execution.which('lsb_release').nil?
        end

        def read_lsb_release_file
          output = Facter::Core::Execution.execute('lsb_release -a', logger: log)
          build_fact_list(output)
        end

        def build_fact_list(info)
          release_info = info.delete("\t").split("\n").map { |e| e.split(':', 2) }

          result = Hash[*release_info.flatten]
          result.each { |k, v| @fact_list[k.downcase.gsub(/\s/, '_').to_sym] = v }

          @fact_list[:identifier] = @fact_list[:distributor_id]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
facter-4.2.5 lib/facter/resolvers/lsb_release.rb
facter-4.2.4 lib/facter/resolvers/lsb_release.rb
facter-4.2.3 lib/facter/resolvers/lsb_release.rb
facter-4.2.2 lib/facter/resolvers/lsb_release.rb