Module: Baptize::Plugins::Execution

Defined in:
lib/baptize/plugins/execution.rb

Instance Method Summary collapse

Instance Method Details

#remote_assert(command) ⇒ Object



33
34
35
36
# File 'lib/baptize/plugins/execution.rb', line 33

def remote_assert(command)
  command = Array(command).flatten.map {|c| "#{c} > /dev/null 2> /dev/null" }.join(" && ")
  call_current_ssh_connection :test, command
end

#remote_capture(*args) ⇒ Object



29
30
31
# File 'lib/baptize/plugins/execution.rb', line 29

def remote_capture(*args)
  call_current_ssh_connection :capture, *args
end

#remote_execute(*args) ⇒ Object



25
26
27
# File 'lib/baptize/plugins/execution.rb', line 25

def remote_execute(*args)
  call_current_ssh_connection :execute, *args
end

#run_locally(cmd) ⇒ Object

logs the command then executes it locally. returns the command output as a string



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/baptize/plugins/execution.rb', line 9

def run_locally(cmd)
  if fetch(:dry_run)
    return logger.debug "executing locally: #{cmd.inspect}"
  end
  logger.trace "executing locally: #{cmd.inspect}" if logger
  output_on_stdout = nil
  elapsed = Benchmark.realtime do
    output_on_stdout = `#{cmd}`
  end
  if $?.to_i > 0 # $? is command exit code (posix style)
    raise ArgumentError, "Command #{cmd} returned status code #{$?}"
  end
  logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger
  output_on_stdout
end