Class: Kafo::FactWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/fact_writer.rb

Constant Summary collapse

DATA_FILENAME =
'kafo.yaml'
WRAPPER_FILENAME =
'kafo.rb'

Class Method Summary collapse

Class Method Details

.wrapperObject



16
17
18
19
20
21
22
# File 'lib/kafo/fact_writer.rb', line 16

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

.write_facts(facts, directory) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/kafo/fact_writer.rb', line 6

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