# canzea --role=operatingsystem --solution=centos --remote --hostname=192.34.56.119 --privateKey=/var/go/.ssh/id_rsa_digitalocean require 'net/ssh' require 'net/sftp' require 'json' class RemoteCall def exec (hostname, privateKey, cmd) @username = "root" Net::SSH.start(hostname, @username, :paranoid => false, :keys => [privateKey]) do |ssh| chan = ssh.open_channel do |channel| channel.request_pty channel.env("DIGITAL_OCEAN_API_KEY", ENV['DIGITAL_OCEAN_API_KEY']) channel.env("VAULT_TOKEN", ENV['VAULT_TOKEN']) channel.env("CONSUL_URL", ENV['CONSUL_URL']) channel.env("WORK_DIR", ENV['WORK_DIR']) channel.exec(cmd) do |ch, success| abort "could not execute command" unless success channel.on_data do |ch, data| puts data end channel.on_request("exit-status") do |ch, data| exit_code = data.read_long if (exit_code == 0) else abort() end end channel.on_close do |ch| end end end chan.wait end end end