Module: Puppet::Configurer::FactHandler

Included in:
Puppet::Configurer
Defined in:
lib/vendor/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

#download_fact_pluginsObject

Retrieve facts from the central server.



48
49
50
51
52
53
54
55
# File 'lib/vendor/puppet/configurer/fact_handler.rb', line 48

def download_fact_plugins
  return unless download_fact_plugins?

  # Deprecated prior to 0.25, as of 5/19/2008
  Puppet.warning "Fact syncing is deprecated as of 0.25 -- use 'pluginsync' instead"

  Puppet::Configurer::Downloader.new("fact", Puppet[:factdest], Puppet[:factsource], Puppet[:factsignore]).evaluate
end

#download_fact_plugins?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/vendor/puppet/configurer/fact_handler.rb', line 9

def download_fact_plugins?
  Puppet[:factsync]
end

#facts_for_uploadingObject



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

def facts_for_uploading
  facts = find_facts
  #format = facts.class.default_format

  if facts.support_format?(:b64_zlib_yaml)
    format = :b64_zlib_yaml
  else
    format = :yaml
  end

  text = facts.render(format)

  {:facts_format => format, :facts => CGI.escape(text)}
end

#find_factsObject



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

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])
    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
    puts detail.backtrace if Puppet[:trace]
    raise Puppet::Error, "Could not retrieve local facts: #{detail}"
  end
end