Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

Commit

Permalink
Merge pull request #25 from reset/sudo-pty
Browse files Browse the repository at this point in the history
a pty will be requested if sudo is attempted to run
  • Loading branch information
reset committed Nov 26, 2012
2 parents 1025077 + 99bf3ce commit 5f4f7b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/ridley/bootstrapper.rb
Expand Up @@ -60,7 +60,8 @@ def initialize(hosts, options = {})
user: options.fetch(:ssh_user),
password: options[:ssh_password],
keys: options[:ssh_keys],
timeout: (options[:ssh_timeout] || 1.5)
timeout: (options[:ssh_timeout] || 1.5),
sudo: (options[:sudo].nil? ? true : options[:sudo])
}

@contexts = @hosts.collect do |host|
Expand Down
15 changes: 11 additions & 4 deletions lib/ridley/ssh/worker.rb
Expand Up @@ -5,11 +5,16 @@ class SSH
class Worker
include Celluloid
include Celluloid::Logger

attr_reader :sudo
attr_reader :user
attr_reader :options

# @param [Hash] options
def initialize(options = {})
@sudo = options.delete(:sudo)
@user = options[:user]
@options = options
@user = options.fetch(:user)
end

# @param [String] host
Expand All @@ -22,6 +27,10 @@ def run(host, command)

Net::SSH.start(host, user, options) do |ssh|
ssh.open_channel do |channel|
if self.sudo
channel.request_pty
end

channel.exec(command) do |ch, success|
unless success
raise "FAILURE: could not execute command"
Expand Down Expand Up @@ -58,14 +67,12 @@ def run(host, command)
end
rescue => e
debug "Failed to run SSH command: '#{command}' on: '#{host}' as: '#{user}'"
[ :error, e.message ]
[ :error, e ]
end

private

attr_reader :runner
attr_reader :user
attr_reader :options
end
end
end
14 changes: 14 additions & 0 deletions spec/unit/ridley/ssh/worker_spec.rb
@@ -0,0 +1,14 @@
require 'spec_helper'

describe Ridley::SSH::Worker do
describe "ClassMethods" do
subject { described_class }

describe "::new" do
it { subject.new(sudo: true).sudo.should be_true }
it { subject.new(sudo: false).sudo.should be_false }
it { subject.new().sudo.should be_false }
it { subject.new(sudo: true).options.should_not have_key(:sudo) }
end
end
end

0 comments on commit 5f4f7b9

Please sign in to comment.