Class: Puppet::Node::Facts::Facter

Inherits:
Indirector::Code show all
Defined in:
lib/puppet/indirector/facts/facter.rb

Constant Summary

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::RFC_3986_URI_REGEX

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Indirector::Terminus

abstract_terminus?, const2name, #indirection, indirection_name, inherited, #initialize, mark_as_abstract_terminus, model, #model, #name, name2const, register_terminus_class, terminus_class, terminus_classes, #terminus_type, #validate, #validate_key, #validate_model

Methods included from Util::InstanceLoader

#instance_hash, #instance_load, #instance_loader, #instance_loading?, #loaded_instance, #loaded_instances

Methods included from Util

absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, which, withenv, withumask

Methods included from Util::SymbolicFileMode

#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods included from Util::POSIX

#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Constructor Details

This class inherits a constructor from Puppet::Indirector::Terminus

Class Method Details

.setup_external_search_paths(request) ⇒ Object


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/puppet/indirector/facts/facter.rb', line 68

def self.setup_external_search_paths(request)
  # Add any per-module external fact directories to facter's external search path
  dirs = []
  request.environment.modules.each do |m|
    if m.has_external_facts?
      dir = m.plugin_fact_directory
      Puppet.debug "Loading external facts from #{dir}"
      dirs << dir
    end
  end

  # Add system external fact directory if it exists
  if FileTest.directory?(Puppet[:pluginfactdest])
    dir = Puppet[:pluginfactdest]
    Puppet.debug "Loading external facts from #{dir}"
    dirs << dir
  end

  Facter.search_external dirs
end

.setup_search_paths(request) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/puppet/indirector/facts/facter.rb', line 41

def self.setup_search_paths(request)
  # Add any per-module fact directories to facter's search path
  dirs = request.environment.modulepath.collect do |dir|
    ['lib', 'plugins'].map do |subdirectory|
      Dir.glob("#{dir}/*/#{subdirectory}/facter")
    end
  end.flatten + Puppet[:factpath].split(File::PATH_SEPARATOR)

  dirs = dirs.select do |dir|
    next false unless FileTest.directory?(dir)

    # Even through we no longer directly load facts in the terminus,
    # print out each .rb in the facts directory as module
    # developers may find that information useful for debugging purposes
    if Puppet::Util::Log.sendlevel?(:info)
      Puppet.info _("Loading facts")
      Dir.glob("#{dir}/*.rb").each do |file|
        Puppet.debug "Loading facts from #{file}"
      end
    end

    true
  end

  Facter.search(*dirs)
end

Instance Method Details

#allow_remote_requests?Boolean


9
10
11
# File 'lib/puppet/indirector/facts/facter.rb', line 9

def allow_remote_requests?
  false
end

#destroy(facts) ⇒ Object

Raises:


13
14
15
# File 'lib/puppet/indirector/facts/facter.rb', line 13

def destroy(facts)
  raise Puppet::DevError, _('You cannot destroy facts in the code store; it is only used for getting facts from Facter')
end

#find(request) ⇒ Object

Lookup a host's facts up in Facter.


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/puppet/indirector/facts/facter.rb', line 22

def find(request)
  Facter.reset

  # Note: we need to setup puppet's external search paths before adding the puppetversion
  # fact. This is because in Facter 2.x, the first `Facter.add` causes Facter to create
  # its directory loaders which cannot be changed, meaning other external facts won't
  # be resolved. (PUP-4607)
  self.class.setup_external_search_paths(request)
  self.class.setup_search_paths(request)

  # Initialize core Puppet facts, such as puppetversion
  Puppet.initialize_facts

  result = Puppet::Node::Facts.new(request.key, Facter.to_hash)
  result.add_local_facts
  result.sanitize
  result
end

#save(facts) ⇒ Object

Raises:


17
18
19
# File 'lib/puppet/indirector/facts/facter.rb', line 17

def save(facts)
  raise Puppet::DevError, _('You cannot save facts to the code store; it is only used for getting facts from Facter')
end