2011-07-01 02:48:18 +00:00
|
|
|
require 'guard/puppet'
|
|
|
|
require 'puppet/util/command_line'
|
|
|
|
require 'puppet/application/apply'
|
2011-07-05 23:43:36 +00:00
|
|
|
require 'guard/puppet/log'
|
2011-07-01 02:48:18 +00:00
|
|
|
|
|
|
|
module Guard
|
|
|
|
class Puppet
|
|
|
|
class Runner
|
|
|
|
attr_reader :options
|
|
|
|
|
|
|
|
def initialize(options)
|
2011-07-01 03:16:16 +00:00
|
|
|
@options = {
|
|
|
|
:verbose => true,
|
|
|
|
:manifest => 'manifests/site.pp'
|
|
|
|
}.merge(options)
|
2011-07-05 23:43:36 +00:00
|
|
|
|
2011-07-01 02:48:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2011-07-05 23:43:36 +00:00
|
|
|
messages = ::Puppet::Util::Log.newdestination(:guard)
|
|
|
|
|
|
|
|
begin
|
|
|
|
maybe_bundle_with_env do
|
|
|
|
::Puppet::Util::CommandLine.new('puppet', command_line_params).execute
|
|
|
|
end
|
|
|
|
0
|
|
|
|
rescue SystemExit => e
|
|
|
|
if e.status == 0
|
|
|
|
if messages.has_failed?
|
|
|
|
1
|
|
|
|
else
|
|
|
|
0
|
|
|
|
end
|
|
|
|
else
|
|
|
|
e.status
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
::Puppet::Util::Log.close(:guard)
|
|
|
|
end
|
2011-07-01 02:48:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def command_line_params
|
2011-07-01 03:16:16 +00:00
|
|
|
command = [ "apply", %{--confdir="#{Dir.pwd}"} ]
|
2011-07-01 02:48:18 +00:00
|
|
|
command << "-v" if @options[:verbose]
|
2011-07-05 23:43:36 +00:00
|
|
|
command << "-d" if @options[:debug]
|
2011-07-01 02:48:18 +00:00
|
|
|
command << @options[:manifest] if @options[:manifest]
|
|
|
|
command
|
|
|
|
end
|
2011-07-05 23:43:36 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
def maybe_bundle_with_env(&block)
|
|
|
|
if defined?(::Bundler)
|
|
|
|
Bundler.with_clean_env(&block)
|
|
|
|
else
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
2011-07-01 02:48:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|