X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=plugins%2Fmcollective%2Ffacts%2Fyaml_facts.rb;fp=plugins%2Fmcollective%2Ffacts%2Fyaml_facts.rb;h=57d33d495330feade840571a1d9a5e9df87110d6;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/plugins/mcollective/facts/yaml_facts.rb b/plugins/mcollective/facts/yaml_facts.rb new file mode 100644 index 0000000..57d33d4 --- /dev/null +++ b/plugins/mcollective/facts/yaml_facts.rb @@ -0,0 +1,61 @@ +module MCollective + module Facts + require 'yaml' + + # 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. + class Yaml_facts e + Log.error("Failed to load yaml facts from #{file}: #{e.class}: #{e}") + end + end + + facts + end + + # force fact reloads when the mtime on the yaml file change + def force_reload? + config = Config.instance + + fact_files = config.pluginconf["yaml"].split(File::PATH_SEPARATOR) + + fact_files.each do |file| + @yaml_file_mtimes[file] ||= File.stat(file).mtime + mtime = File.stat(file).mtime + + if mtime > @yaml_file_mtimes[file] + @yaml_file_mtimes[file] = mtime + + Log.debug("Forcing fact reload due to age of #{file}") + + return true + end + end + + false + end + end + end +end