| Class | MCollective::Facts::Yaml_facts |
| In: |
plugins/mcollective/facts/yaml_facts.rb
|
| Parent: | Base |
A factsource that reads a hash of facts from a YAML file
Multiple files can be specified seperated with a : in the config file, they will be merged with later files overriding earlier ones in the list.
# File plugins/mcollective/facts/yaml_facts.rb, line 11
11: def initialize
12: @yaml_file_mtimes = {}
13:
14: super
15: end
force fact reloads when the mtime on the yaml file change
# File plugins/mcollective/facts/yaml_facts.rb, line 39
39: def force_reload?
40: config = Config.instance
41:
42: fact_files = config.pluginconf["yaml"].split(":")
43:
44: fact_files.each do |file|
45: @yaml_file_mtimes[file] ||= File.stat(file).mtime
46: mtime = File.stat(file).mtime
47:
48: if mtime > @yaml_file_mtimes[file]
49: @yaml_file_mtimes[file] = mtime
50:
51: Log.debug("Forcing fact reload due to age of #{file}")
52:
53: return true
54: end
55: end
56:
57: false
58: end
# File plugins/mcollective/facts/yaml_facts.rb, line 17
17: def load_facts_from_source
18: config = Config.instance
19:
20: fact_files = config.pluginconf["yaml"].split(":")
21: facts = {}
22:
23: fact_files.each do |file|
24: begin
25: if File.exist?(file)
26: facts.merge!(YAML.load_file(file))
27: else
28: raise("Can't find YAML file to load: #{file}")
29: end
30: rescue Exception => e
31: Log.error("Failed to load yaml facts from #{file}: #{e.class}: #{e}")
32: end
33: end
34:
35: facts
36: end