class AvoDeploy::Task::RemoteTaskExecutionEnvironment
Attributes
config[RW]
Public Instance Methods
check_util_availability(utils)
click to toggle source
Checks, if all utilities are available for the deployment process to be executed
@param utils [Array] array with utilities to check
Calls superclass method
# File lib/avodeploy/task/remote_task_execution_environment.rb, line 40 def check_util_availability(utils) super(utils, 'remotely') end
command(cmd)
click to toggle source
Executes a command on the remote system
@param cmd [String] the command to execute @return [CommandExecutionResult] result of the command exection
# File lib/avodeploy/task/remote_task_execution_environment.rb, line 86 def command(cmd) AvoDeploy::Deployment.instance.log.info "Executing [" + cmd.yellow + "] on remote " + get(:name).to_s.cyan result = AvoDeploy::CommandExecutionResult.new begin result = ssh_exec!(@session, cmd) if result.stdout.nil? == false && result.stdout.empty? == false AvoDeploy::Deployment.instance.log.debug "Stdout@#{get(:host)}: ".cyan + result.stdout.green end if result.stderr.nil? == false && result.stderr.empty? == false AvoDeploy::Deployment.instance.log.debug "Stderr@#{get(:host)}: ".cyan + result.stderr.red end rescue Exception => e handle_abort e end result end
establish_connection()
click to toggle source
Creates a connection between the local and the remote system over ssh
# File lib/avodeploy/task/remote_task_execution_environment.rb, line 26 def establish_connection AvoDeploy::Deployment.instance.log.debug "connecting to #{get(:user)}@#{get(:host)}..." begin @session = ::Net::SSH.start(get(:host), get(:user), port: get(:port), timeout: 30, auth_methods: [ 'publickey', 'hostbased' ]) rescue ::Net::SSH::AuthenticationFailed => e handle_abort e end end
ssh_exec!(ssh, command)
click to toggle source
Executes a command via ssh @param ssh [Net::SSH::Connection::Session] ssh session
@param command [String] the command to execute
# File lib/avodeploy/task/remote_task_execution_environment.rb, line 48 def ssh_exec!(ssh, command) stdout_data = "" stderr_data = "" exit_code = nil ssh.open_channel do |channel| channel.exec(command) do |ch, success| unless success abort "FAILED: couldn't execute command (ssh.channel.exec)" end channel.on_data do |ch, data| stdout_data+=data end channel.on_extended_data do |ch, type, data| stderr_data+=data end channel.on_request("exit-status") do |ch, data| exit_code = data.read_long end end end ssh.loop result = AvoDeploy::CommandExecutionResult.new result.stdin = command result.stdout = stdout_data result.stderr = stderr_data result.retval = exit_code result end