class Facts::Facter
Public Class Methods
setup_external_search_paths(request)
click to toggle source
# File lib/puppet/indirector/facts/facter.rb 82 def self.setup_external_search_paths(request) 83 # Add any per-module external fact directories to facter's external search path 84 dirs = [] 85 request.environment.modules.each do |m| 86 if m.has_external_facts? 87 dir = m.plugin_fact_directory 88 Puppet.debug { "Loading external facts from #{dir}" } 89 dirs << dir 90 end 91 end 92 93 # Add system external fact directory if it exists 94 if FileTest.directory?(Puppet[:pluginfactdest]) 95 dir = Puppet[:pluginfactdest] 96 Puppet.debug { "Loading external facts from #{dir}" } 97 dirs << dir 98 end 99 100 dirs << request.options[:external_dir] if request.options[:external_dir] 101 Puppet.runtime[:facter].search_external dirs 102 end
setup_search_paths(request)
click to toggle source
# File lib/puppet/indirector/facts/facter.rb 55 def self.setup_search_paths(request) 56 # Add any per-module fact directories to facter's search path 57 dirs = request.environment.modulepath.collect do |dir| 58 ['lib', 'plugins'].map do |subdirectory| 59 Dir.glob("#{dir}/*/#{subdirectory}/facter") 60 end 61 end.flatten + Puppet[:factpath].split(File::PATH_SEPARATOR) 62 63 dirs = dirs.select do |dir| 64 next false unless FileTest.directory?(dir) 65 66 # Even through we no longer directly load facts in the terminus, 67 # print out each .rb in the facts directory as module 68 # developers may find that information useful for debugging purposes 69 if Puppet::Util::Log.sendlevel?(:info) 70 Puppet.info _("Loading facts") 71 Dir.glob("#{dir}/*.rb").each do |file| 72 Puppet.debug { "Loading facts from #{file}" } 73 end 74 end 75 76 true 77 end 78 dirs << request.options[:custom_dir] if request.options[:custom_dir] 79 Puppet.runtime[:facter].search(*dirs) 80 end
Public Instance Methods
allow_remote_requests?()
click to toggle source
# File lib/puppet/indirector/facts/facter.rb 10 def allow_remote_requests? 11 false 12 end
destroy(facts)
click to toggle source
# File lib/puppet/indirector/facts/facter.rb 14 def destroy(facts) 15 raise Puppet::DevError, _('You cannot destroy facts in the code store; it is only used for getting facts from Facter') 16 end
find(request)
click to toggle source
Lookup a host's facts up in Facter.
# File lib/puppet/indirector/facts/facter.rb 23 def find(request) 24 Puppet.runtime[:facter].reset 25 26 # Note: we need to setup puppet's external search paths before adding the puppetversion 27 # fact. This is because in Facter 2.x, the first `Puppet.runtime[:facter].add` causes Facter to create 28 # its directory loaders which cannot be changed, meaning other external facts won't 29 # be resolved. (PUP-4607) 30 self.class.setup_external_search_paths(request) 31 self.class.setup_search_paths(request) 32 33 # Initialize core Puppet facts, such as puppetversion 34 Puppet.initialize_facts 35 36 result = if request.options[:resolve_options] 37 raise(Puppet::Error, _("puppet facts show requires version 4.0.40 or greater of Facter.")) unless Facter.respond_to?(:resolve) 38 find_with_options(request) 39 elsif Puppet[:include_legacy_facts] 40 # to_hash returns both structured and legacy facts 41 Puppet::Node::Facts.new(request.key, Puppet.runtime[:facter].to_hash) 42 else 43 # resolve does not return legacy facts unless requested 44 facts = Puppet.runtime[:facter].resolve('') 45 # some versions of Facter 4 return a Facter::FactCollection instead of 46 # a Hash, breaking API compatibility, so force a hash using `to_h` 47 Puppet::Node::Facts.new(request.key, facts.to_h) 48 end 49 50 result.add_local_facts unless request.options[:resolve_options] 51 result.sanitize 52 result 53 end
save(facts)
click to toggle source
# File lib/puppet/indirector/facts/facter.rb 18 def save(facts) 19 raise Puppet::DevError, _('You cannot save facts to the code store; it is only used for getting facts from Facter') 20 end
Private Instance Methods
find_with_options(request)
click to toggle source
# File lib/puppet/indirector/facts/facter.rb 106 def find_with_options(request) 107 options = request.options 108 options_for_facter = String.new 109 options_for_facter += options[:user_query].join(' ') 110 options_for_facter += " --config #{options[:config_file]}" if options[:config_file] 111 options_for_facter += " --show-legacy" if options[:show_legacy] 112 options_for_facter += " --no-block" if options[:no_block] == false 113 options_for_facter += " --no-cache" if options[:no_cache] == false 114 options_for_facter += " --timing" if options[:timing] 115 116 Puppet::Node::Facts.new(request.key, Puppet.runtime[:facter].resolve(options_for_facter)) 117 end