module PuppetFactset
Constants
- MERGE_FACTS_DIR
- VERSION
Public Class Methods
factset_dir()
click to toggle source
Return the name of the directory holding the factsets
# File lib/puppet_factset.rb, line 9 def self.factset_dir File.expand_path(File.join(File.dirname(__FILE__), '..', 'res', 'factset')) end
factset_hash(factset_name)
click to toggle source
Load factset json file and return a hash
# File lib/puppet_factset.rb, line 14 def self.factset_hash(factset_name) data = JSON.parse(File.read(File.join(factset_dir(), "#{factset_name}.json"))) merge_facts(data["values"]) # The facts are tucked away inside the 'values' element so just return that data["values"] end
factsets()
click to toggle source
List the available factsets, sorted A-Z
# File lib/puppet_factset.rb, line 24 def self.factsets() Dir.glob(File.join(factset_dir, '*.json')).map { |f| File.basename(f).gsub('.json','') }.sort end
merge_facts(factset)
click to toggle source
If a directory exists at `merge_facts` relative to the current directory then all JSON files present in this directory will be loaded and merged into passed in factset
@param factset Hash of facts (will be modified in-place)
# File lib/puppet_factset.rb, line 35 def self.merge_facts(factset) Dir["#{MERGE_FACTS_DIR}/*.json"].each { |json_file| facts = JSON.parse(File.read(json_file)) factset.merge!(facts) } end