Sha256: b05037a408f9b65dddd6997129a3bd0b39fc926d5882b78793108c9cacb234b0

Contents?: true

Size: 679 Bytes

Versions: 10

Compression:

Stored size: 679 Bytes

Contents

module Kafo
  class FactWriter
    DATA_FILENAME = 'kafo.yaml'
    WRAPPER_FILENAME = 'kafo.rb'

    def self.write_facts(facts, directory)
      Dir.mkdir(directory)

      # Write a data file containing all the facts encoded as YAML
      File.open(File.join(directory, DATA_FILENAME), 'w') { |f| f.write(YAML.dump(facts)) }

      # Write a Ruby wrapper since only those are executed within puppet
      File.open(File.join(directory, 'kafo.rb'), 'w') { |f| f.write(wrapper) }
    end

    def self.wrapper
      <<~WRAPPER
        require 'yaml'
        Facter.add(:kafo) { setcode { YAML.load_file(File.join(__dir__, '#{DATA_FILENAME}')) } }
      WRAPPER
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kafo-7.6.0 lib/kafo/fact_writer.rb
kafo-7.5.1 lib/kafo/fact_writer.rb
kafo-7.5.0 lib/kafo/fact_writer.rb
kafo-7.4.0 lib/kafo/fact_writer.rb
kafo-7.3.0 lib/kafo/fact_writer.rb
kafo-7.2.0 lib/kafo/fact_writer.rb
kafo-7.1.0 lib/kafo/fact_writer.rb
kafo-7.0.0 lib/kafo/fact_writer.rb
kafo-6.5.0 lib/kafo/fact_writer.rb
kafo-6.4.1 lib/kafo/fact_writer.rb