Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support handle sudo password #51

Merged
merged 1 commit into from Apr 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/serverspec.rb
Expand Up @@ -17,6 +17,7 @@
c.include(Serverspec::Helper::Debian, :os => :debian)
c.include(Serverspec::Helper::Gentoo, :os => :gentoo)
c.include(Serverspec::Helper::Solaris, :os => :solaris)
c.add_setting :host, :default => nil
c.add_setting :ssh, :default => nil
c.add_setting :host, :default => nil
c.add_setting :ssh, :default => nil
c.add_setting :sudo_password, :default => nil
end
15 changes: 11 additions & 4 deletions lib/serverspec/backend/ssh.rb
Expand Up @@ -22,15 +22,22 @@ def ssh_exec!(command)
end
channel.exec("#{command}") do |ch, success|
abort "FAILED: couldn't execute command (ssh.channel.exec)" if !success
channel.on_data do |ch,data|
stdout_data += data
channel.on_data do |ch, data|
if data =~ /^\[sudo\] password for/
channel.send_data "#{RSpec.configuration.sudo_password}\n"
channel.on_data do |ch, data|
stdout_data += data
end
else
stdout_data += data
end
end

channel.on_extended_data do |ch,type,data|
channel.on_extended_data do |ch, type, data|
stderr_data += data
end

channel.on_request("exit-status") do |ch,data|
channel.on_request("exit-status") do |ch, data|
exit_code = data.read_long
end

Expand Down