summaryrefslogtreecommitdiffstats
path: root/lib/puppet/configurer/plugin_handler.rb
blob: 539441e759f66183766ed22ef63ebaa8f44801c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Break out the code related to plugins.  This module is
# just included into the agent, but having it here makes it
# easier to test.
module Puppet::Configurer::PluginHandler
  def download_plugins?
    Puppet[:pluginsync]
  end

  # Retrieve facts from the central server.
  def download_plugins
    return nil unless download_plugins?
    Puppet::Configurer::Downloader.new("plugin", Puppet[:plugindest], Puppet[:pluginsource], Puppet[:pluginsignore]).evaluate.each { |file| load_plugin(file) }
  end

  def load_plugin(file)
    return unless FileTest.exist?(file)
    return if FileTest.directory?(file)

    begin
      Puppet.info "Loading downloaded plugin #{file}"
      load file
    rescue SystemExit,NoMemoryError
      raise
    rescue Exception => detail
      Puppet.err "Could not load downloaded file #{file}: #{detail}"
    end
  end
end