1
require 'puppet/indirector/facts/facter'
3
require 'puppet/configurer/downloader'
5
# Break out the code related to facts. This module is
6
# just included into the agent, but having it here makes it
8
module Puppet::Configurer::FactHandler
9
def download_fact_plugins?
16
# This works because puppetd configures Facts to use 'facter' for
17
# finding facts and the 'rest' terminus for caching them. Thus, we'll
18
# compile them and then "cache" them on the server.
20
Puppet::Node::Facts.find(Puppet[:certname])
22
puts detail.backtrace if Puppet[:trace]
23
raise Puppet::Error, "Could not retrieve local facts: %s" % detail
27
def facts_for_uploading
29
#format = facts.class.default_format
31
# Hard-code yaml, because I couldn't get marshal to work.
32
format = :b64_zlib_yaml
34
text = facts.render(format)
36
return {:facts_format => :b64_zlib_yaml, :facts => CGI.escape(text)}
39
# Retrieve facts from the central server.
40
def download_fact_plugins
41
return unless download_fact_plugins?
43
# Deprecated prior to 0.25, as of 5/19/2008
44
Puppet.warning "Fact syncing is deprecated as of 0.25 -- use 'pluginsync' instead"
46
Puppet::Configurer::Downloader.new("fact", Puppet[:factdest], Puppet[:factsource], Puppet[:factsignore]).evaluate
49
# Clear out all of the loaded facts and reload them from disk.
50
# NOTE: This is clumsy and shouldn't be required for later (1.5.x) versions
56
if Facter.respond_to? :loadfacts
58
elsif Facter.respond_to? :load
61
Puppet.warning "You should upgrade your version of Facter to at least 1.3.8"
64
# This loads all existing facts and any new ones. We have to remove and
65
# reload because there's no way to unload specific facts.
66
Puppet::Node::Facts::Facter.load_fact_plugins()