~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to lib/puppet/configurer/fact_handler.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'puppet/indirector/facts/facter'
 
2
 
 
3
require 'puppet/configurer/downloader'
 
4
 
 
5
# Break out the code related to facts.  This module is
 
6
# just included into the agent, but having it here makes it
 
7
# easier to test.
 
8
module Puppet::Configurer::FactHandler
 
9
    def download_fact_plugins?
 
10
        Puppet[:factsync]
 
11
    end
 
12
 
 
13
    def find_facts
 
14
        reload_facter()
 
15
 
 
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.
 
19
        begin
 
20
            Puppet::Node::Facts.find(Puppet[:certname])
 
21
        rescue => detail
 
22
            puts detail.backtrace if Puppet[:trace]
 
23
            raise Puppet::Error, "Could not retrieve local facts: %s" % detail
 
24
        end
 
25
    end
 
26
 
 
27
    def facts_for_uploading
 
28
        facts = find_facts
 
29
        #format = facts.class.default_format
 
30
 
 
31
        # Hard-code yaml, because I couldn't get marshal to work.
 
32
        format = :b64_zlib_yaml
 
33
 
 
34
        text = facts.render(format)
 
35
 
 
36
        return {:facts_format => :b64_zlib_yaml, :facts => CGI.escape(text)}
 
37
    end
 
38
 
 
39
    # Retrieve facts from the central server.
 
40
    def download_fact_plugins
 
41
        return unless download_fact_plugins?
 
42
 
 
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"
 
45
 
 
46
        Puppet::Configurer::Downloader.new("fact", Puppet[:factdest], Puppet[:factsource], Puppet[:factsignore]).evaluate
 
47
    end
 
48
 
 
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
 
51
    # of Facter.
 
52
    def reload_facter
 
53
        Facter.clear
 
54
 
 
55
        # Reload everything.
 
56
        if Facter.respond_to? :loadfacts
 
57
            Facter.loadfacts
 
58
        elsif Facter.respond_to? :load
 
59
            Facter.load
 
60
        else
 
61
            Puppet.warning "You should upgrade your version of Facter to at least 1.3.8"
 
62
        end
 
63
 
 
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()
 
67
    end
 
68
end