hacking ssh to work for sudo commands

This commit is contained in:
geemus (Wesley Beary) 2010-04-18 21:42:08 -07:00
parent 2d974313aa
commit 09f7f9fc4f
1 changed files with 15 additions and 4 deletions

View File

@ -16,11 +16,22 @@ module Fog
results = []
Net::SSH.start(@address, @username, @options) do |ssh|
commands.each do |command|
result = { :command => command }
ssh.exec!(command) do |channel, stream, data|
result[stream] = data
ssh.open_channel do |channel|
channel.request_pty
result = { :command => command }
channel.exec(command.sub(/^sudo/, %q{sudo -p 'fog sudo password:'})) do |channel, success|
channel.on_data do |channel, data|
if data.strip == 'fog sudo password:'
channel.send_data("#{@options[:password]}\n")
else
result[:data] ||= ''
result[:data] << data
end
end
end
results << result
end
results << result
ssh.loop
end
end
results