summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/application/puppet.rb10
-rw-r--r--lib/puppet/configurer.rb24
-rw-r--r--lib/puppet/defaults.rb7
3 files changed, 37 insertions, 4 deletions
diff --git a/lib/puppet/application/puppet.rb b/lib/puppet/application/puppet.rb
index 2929d54e8..273c7d0e7 100644
--- a/lib/puppet/application/puppet.rb
+++ b/lib/puppet/application/puppet.rb
@@ -1,5 +1,6 @@
require 'puppet'
require 'puppet/application'
+require 'puppet/configurer'
require 'puppet/network/handler'
require 'puppet/network/client'
@@ -124,9 +125,14 @@ Puppet::Application.new(:puppet) do
catalog.retrieval_duration = Time.now - starttime
+ configurer = Puppet::Configurer.new
+ configurer.execute_prerun_command
+
# And apply it
transaction = catalog.apply
+ configurer.execute_postrun_command
+
status = 0
if not Puppet[:noop] and options[:detailed_exitcodes] then
transaction.generate_report
@@ -135,9 +141,7 @@ Puppet::Application.new(:puppet) do
end
exit(status)
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
if detail.is_a?(XMLRPC::FaultException)
$stderr.puts detail.message
else
diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb
index 3e72fa574..ec61272ef 100644
--- a/lib/puppet/configurer.rb
+++ b/lib/puppet/configurer.rb
@@ -5,6 +5,8 @@ require 'puppet/network/http_pool'
require 'puppet/util'
class Puppet::Configurer
+ class CommandHookError < RuntimeError; end
+
require 'puppet/configurer/fact_handler'
require 'puppet/configurer/plugin_handler'
@@ -39,6 +41,14 @@ class Puppet::Configurer
@catalog = nil
end
+ def execute_postrun_command
+ execute_from_setting(:postrun_command)
+ end
+
+ def execute_prerun_command
+ execute_from_setting(:prerun_command)
+ end
+
# Initialize and load storage
def dostorage
begin
@@ -75,6 +85,8 @@ class Puppet::Configurer
download_plugins()
download_fact_plugins()
+
+ execute_prerun_command
end
# Get the remote catalog, yo. Returns nil if no catalog can be found.
@@ -160,6 +172,8 @@ class Puppet::Configurer
# Now close all of our existing http connections, since there's no
# reason to leave them lying open.
Puppet::Network::HttpPool.clear_http_instances
+ ensure
+ execute_postrun_command
end
private
@@ -180,4 +194,14 @@ class Puppet::Configurer
return timeout
end
+
+ def execute_from_setting(setting)
+ return if (command = Puppet[setting]) == ""
+
+ begin
+ Puppet::Util.execute([command])
+ rescue => detail
+ raise CommandHookError, "Could not run command from #{setting}: #{detail}"
+ end
+ end
end
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 6b9c43b81..21cee7a05 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -199,7 +199,12 @@ module Puppet
reports, allowing you to correlate changes on your hosts to the source version on the server."],
:zlib => [true,
"Boolean; whether to use the zlib library",
- ]
+ ],
+ :prerun_command => ["", "A command to run before every agent run. If this command returns a non-zero
+ return code, the entire Puppet run will fail."],
+ :postrun_command => ["", "A command to run after every agent run. If this command returns a non-zero
+ return code, the entire Puppet run will be considered to have failed, even though it might have
+ performed work during the normal run."]
)
hostname = Facter["hostname"].value