34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/gaptool-client.rb', line 34
def sshcmd(node, commands)
Net::SSH.start(
node['hostname'],
'admin',
:key_data => [$api.ssh(node['role'], node['environment'], node['instance'])['key']],
:config => false,
:keys_only => true,
:paranoid => false
) do |ssh|
stdout_data = ""
stderr_data = ""
exit_code = nil
exit_signal = nil
commands.each do |command|
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|
puts "#{node['role'].color(:yellow)}:#{node['environment'].color(:yellow)}:#{node['instance'].color(:yellow)}> #{data}"
end
channel.on_extended_data do |ch,type,data|
puts "#{node['role'].color(:yellow)}:#{node['environment'].color(:yellow)}:#{node['instance'].color(:red)}> #{data}"
end
channel.on_request("exit-status") do |ch,data|
exit_code = data.read_long
if exit_code != 0
exit exit_code
end
end
channel.on_request("exit-signal") do |ch, data|
exit_signal = data.read_string
end
end
end
end
end
end
|