class Trooper::Runner
Attributes
config[R]
list[R]
strategy[R]
Public Class Methods
new(strategy, config)
click to toggle source
Public: initialize a new Runner
.
strategy - A Trooper::Strategy
object to execute. config - A Trooper::Configuration
object to use for deployment.
Examples
Runner.new(<Strategy>, <Configuration>) # => <Runner>
Returns a new Runner
object.
# File lib/trooper/runner.rb, line 18 def initialize(strategy, config) @strategy, @config = strategy, config @list = strategy.list config end
Public Instance Methods
execute()
click to toggle source
Public: Executes the strategy across mutiple hosts logging output as it goes.
Examples
@runner.execute # => true
Returns a boolean.
# File lib/trooper/runner.rb, line 30 def execute Trooper.logger.debug "Configuration\n#{config}" Trooper.logger.strategy strategy.description successful = nil hosts.each do |host| begin Trooper.logger.info "\e[4mRunning on #{host}\n" list.each do |strategy_name, type, name| # strategy_name, type, name commands, options = build_commands strategy_name, type, name runner_execute! host, commands, options if commands end successful = true Trooper.logger.success "\e[4mAll Actions Completed\n" rescue Exception => e Trooper.logger.error "#{e.class.to_s} : #{e.message}\n\n#{e.backtrace.join("\n")}" successful = false break #stop commands running on other servers ensure host.close end end successful end
Private Instance Methods
build_commands(strategy_name, type, action_name)
click to toggle source
build the commands to be sent to the host object
# File lib/trooper/runner.rb, line 63 def build_commands(strategy_name, type, action_name) action = Arsenal.actions[action_name] if action options = action.options case type when :prerequisite commands = action.prerequisite_call config Trooper.logger.action "Prerequisite: #{action.description}" else commands = action.call config Trooper.logger.action action.description end [commands, options] else raise MissingActionError, "Cant find action: #{action_name}" end end
hosts()
click to toggle source
returns an array of host objects
# File lib/trooper/runner.rb, line 85 def hosts @hosts ||= begin r, h, u = [], (config[:hosts] rescue nil), (config[:user] rescue nil) h.each {|host| r << Host.new(host, u) } if h && u; r end end
runner_execute!(host, commands, options = {})
click to toggle source
runs the commands on a host and deals with output
# File lib/trooper/runner.rb, line 93 def runner_execute!(host, commands, options = {}) result = host.execute commands, options if result && result[1] == :stdout Trooper.logger.info "#{result[2]}\n" true else false end end