Created
February 27, 2010 05:19
-
-
Save mdeiters/316490 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Capistrano | |
class SSH | |
class << self | |
alias :original_connect :connect | |
def connect(server, options={}, &block) | |
special_server_settings = options[:server_authentication] ? options[:server_authentication][server.to_s] : nil | |
if special_server_settings.nil? | |
return original_connect(server, options, &block) | |
else | |
methods = [ %w(publickey hostbased), %w(password keyboard-interactive) ] | |
password_value = nil | |
ssh_options = (options[:ssh_options] || {}).dup | |
ssh_options[:username] = special_server_settings[:user] || server.user || options[:user] || ssh_options[:username] | |
ssh_options[:port] = server.port || options[:port] || ssh_options[:port] || DEFAULT_PORT | |
begin | |
connection_options = ssh_options.merge( | |
:password => password_value, | |
:auth_methods => ssh_options[:auth_methods] || methods.shift | |
) | |
connection = Net::SSH.start(server.host,connection_options, &block) | |
Server.apply_to(connection, server) | |
rescue Net::SSH::AuthenticationFailed | |
raise if methods.empty? || ssh_options[:auth_methods] | |
password_value = special_server_settings[:password] | |
password_value = password_value.call if password_value.is_a? Proc | |
retry | |
end | |
end | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
role :app, 'thisapp.rocks.com' | |
role :web, 'thisapp.rocks.com' | |
role :db, 'thisdb.rocks.com' | |
role :assets, 'my.asset.server01.com' | |
set :user, 'the-primary-user' | |
set :server_authentication, { 'my.asset.server01.com' => { | |
:user => 'assetusr' , | |
:password => 'password'}} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment