Module: PuppetFactset

Defined in:
lib/puppet_factset.rb,
lib/puppet_factset/version.rb

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.factset_dirObject

Return the name of the directory holding the factsets



6
7
8
# File 'lib/puppet_factset.rb', line 6

def self.factset_dir
  File.expand_path(File.join(File.dirname(__FILE__), '..', 'res', 'factset'))
end

.factset_hash(factset_name) ⇒ Object

Load factset json file and return a hash



11
12
13
14
15
16
# File 'lib/puppet_factset.rb', line 11

def self.factset_hash(factset_name)
  data = JSON.parse(File.read(File.join(factset_dir(), "#{factset_name}.json")))

  # The facts are tucked away inside the 'values' element so just return that
  data["values"]
end

.factsetsObject

List the available factsets, sorted A-Z



19
20
21
22
23
# File 'lib/puppet_factset.rb', line 19

def self.factsets()
  Dir.glob(File.join(factset_dir, '*.json')).map { |f|
    File.basename(f).gsub('.json','')
  }.sort
end