Module: Puppet::Configurer::FactHandler

Included in:
Puppet::Configurer
Defined in:
lib/puppet/configurer/fact_handler.rb

Overview

Break out the code related to facts. This module is just included into the agent, but having it here makes it easier to test.

Instance Method Summary collapse

Instance Method Details

#facts_for_uploadingObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppet/configurer/fact_handler.rb', line 30

def facts_for_uploading
  facts = find_facts

  # NOTE: :facts specified as parameters are URI encoded here,
  # then  encoded for a second time depending on their length:
  #
  # <= 1024 characters sent via query string of a HTTP GET, additionally query string encoded
  # > 1024 characters sent in POST data, additionally x-www-form-urlencoded
  # so it's only important that encoding method here return original values
  # correctly when CGI.unescape called against it (in compiler code)
  if Puppet[:preferred_serialization_format] == "pson"
    {:facts_format => :pson, :facts => Puppet::Util.uri_query_encode(facts.render(:pson)) }
  else
    {:facts_format => 'application/json', :facts => Puppet::Util.uri_query_encode(facts.render(:json)) }
  end
end

#find_factsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet/configurer/fact_handler.rb', line 10

def find_facts
  # This works because puppet agent configures Facts to use 'facter' for
  # finding facts and the 'rest' terminus for caching them.  Thus, we'll
  # compile them and then "cache" them on the server.
  begin
    facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value], :environment => Puppet::Node::Environment.remote(@environment))
    unless Puppet[:node_name_fact].empty?
      Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
      facts.name = Puppet[:node_name_value]
    end
    facts
  rescue SystemExit,NoMemoryError
    raise
  rescue Exception => detail
    message = _("Could not retrieve local facts: %{detail}") % { detail: detail }
    Puppet.log_exception(detail, message)
    raise Puppet::Error, message, detail.backtrace
  end
end