class Facts::Facter

Public Class Methods

setup_external_search_paths(request) click to toggle source
   # File lib/puppet/indirector/facts/facter.rb
74 def self.setup_external_search_paths(request)
75   # Add any per-module external fact directories to facter's external search path
76   dirs = []
77   request.environment.modules.each do |m|
78     if m.has_external_facts?
79       dir = m.plugin_fact_directory
80       Puppet.debug { "Loading external facts from #{dir}" }
81       dirs << dir
82     end
83   end
84 
85   # Add system external fact directory if it exists
86   if FileTest.directory?(Puppet[:pluginfactdest])
87     dir = Puppet[:pluginfactdest]
88     Puppet.debug { "Loading external facts from #{dir}" }
89     dirs << dir
90   end
91 
92   dirs << request.options[:external_dir] if request.options[:external_dir]
93   Facter.search_external dirs
94 end
setup_search_paths(request) click to toggle source
   # File lib/puppet/indirector/facts/facter.rb
47 def self.setup_search_paths(request)
48   # Add any per-module fact directories to facter's search path
49   dirs = request.environment.modulepath.collect do |dir|
50     ['lib', 'plugins'].map do |subdirectory|
51       Dir.glob("#{dir}/*/#{subdirectory}/facter")
52     end
53   end.flatten + Puppet[:factpath].split(File::PATH_SEPARATOR)
54 
55   dirs = dirs.select do |dir|
56     next false unless FileTest.directory?(dir)
57 
58     # Even through we no longer directly load facts in the terminus,
59     # print out each .rb in the facts directory as module
60     # developers may find that information useful for debugging purposes
61     if Puppet::Util::Log.sendlevel?(:info)
62       Puppet.info _("Loading facts")
63       Dir.glob("#{dir}/*.rb").each do |file|
64         Puppet.debug { "Loading facts from #{file}" }
65       end
66     end
67 
68     true
69   end
70   dirs << request.options[:custom_dir] if request.options[:custom_dir]
71   Facter.search(*dirs)
72 end

Public Instance Methods

allow_remote_requests?() click to toggle source
   # File lib/puppet/indirector/facts/facter.rb
 9 def allow_remote_requests?
10   false
11 end
destroy(facts) click to toggle source
   # File lib/puppet/indirector/facts/facter.rb
13 def destroy(facts)
14   raise Puppet::DevError, _('You cannot destroy facts in the code store; it is only used for getting facts from Facter')
15 end
find(request) click to toggle source

Lookup a host's facts up in Facter.

   # File lib/puppet/indirector/facts/facter.rb
22 def find(request)
23   Facter.reset
24 
25   # Note: we need to setup puppet's external search paths before adding the puppetversion
26   # fact. This is because in Facter 2.x, the first `Facter.add` causes Facter to create
27   # its directory loaders which cannot be changed, meaning other external facts won't
28   # be resolved. (PUP-4607)
29   self.class.setup_external_search_paths(request)
30   self.class.setup_search_paths(request)
31 
32   # Initialize core Puppet facts, such as puppetversion
33   Puppet.initialize_facts
34 
35   result = if request.options[:resolve_options]
36              raise(Puppet::Error, _("puppet facts show requires version 4.0.40 or greater of Facter.")) unless Facter.respond_to?(:resolve)
37              find_with_options(request)
38            else
39              Puppet::Node::Facts.new(request.key, Facter.to_hash)
40            end
41 
42   result.add_local_facts unless request.options[:resolve_options]
43   result.sanitize
44   result
45 end
save(facts) click to toggle source
   # File lib/puppet/indirector/facts/facter.rb
17 def save(facts)
18   raise Puppet::DevError, _('You cannot save facts to the code store; it is only used for getting facts from Facter')
19 end

Private Instance Methods

find_with_options(request) click to toggle source
    # File lib/puppet/indirector/facts/facter.rb
 98 def find_with_options(request)
 99   options = request.options
100   options_for_facter = String.new
101   options_for_facter += options[:user_query].join(' ')
102   options_for_facter += " --config #{options[:config_file]}" if options[:config_file]
103   options_for_facter += " --show-legacy" if options[:show_legacy]
104   options_for_facter += " --no-block" if options[:no_block] == false
105   options_for_facter += " --no-cache" if options[:no_cache] == false
106   options_for_facter += " --timing" if options[:timing]
107 
108   Puppet::Node::Facts.new(request.key, Facter.resolve(options_for_facter))
109 end