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
-
#download_fact_plugins ⇒ Object
Retrieve facts from the central server.
- #download_fact_plugins? ⇒ Boolean
- #facts_for_uploading ⇒ Object
- #find_facts ⇒ Object
-
#reload_facter ⇒ Object
Clear out all of the loaded facts and reload them from disk.
Instance Method Details
#download_fact_plugins ⇒ Object
Retrieve facts from the central server.
49 50 51 52 53 54 55 56 |
# File 'lib/puppet/configurer/fact_handler.rb', line 49 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
9 10 11 |
# File 'lib/puppet/configurer/fact_handler.rb', line 9 def download_fact_plugins? Puppet[:factsync] end |
#facts_for_uploading ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet/configurer/fact_handler.rb', line 33 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_facts ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/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 reload_facter facts = Puppet::Node::Facts.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 |
#reload_facter ⇒ Object
Clear out all of the loaded facts and reload them from disk. NOTE: This is clumsy and shouldn’t be required for later (1.5.x) versions of Facter.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/puppet/configurer/fact_handler.rb', line 61 def reload_facter Facter.clear # Reload everything. if Facter.respond_to? :loadfacts Facter.loadfacts elsif Facter.respond_to? :load Facter.load else Puppet.warning "You should upgrade your version of Facter to at least 1.3.8" end # This loads all existing facts and any new ones. We have to remove and # reload because there's no way to unload specific facts. Puppet::Node::Facts::Facter.load_fact_plugins end |