Sha256: 7e316b27152f0e2d609a5734a2f723780836a53fc12a659db1c476883f1e4ff9

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 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?
          output = Facter::Core::Execution.execute('which lsb_release', logger: log)
          @fact_list[:lsb_release_installed] = !output.empty?
        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

7 entries across 7 versions & 1 rubygems

Version Path
facter-4.2.1 lib/facter/resolvers/lsb_release.rb
facter-4.2.0 lib/facter/resolvers/lsb_release.rb
facter-4.1.1 lib/facter/resolvers/lsb_release.rb
facter-4.1.0 lib/facter/resolvers/lsb_release.rb
facter-4.0.52 lib/facter/resolvers/lsb_release.rb
facter-4.0.51 lib/facter/resolvers/lsb_release.rb
facter-4.0.50 lib/facter/resolvers/lsb_release.rb