summaryrefslogtreecommitdiff
path: root/lib/chef/knife/ssh.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-01-17 13:43:28 -0800
committerdanielsdeleo <dan@opscode.com>2013-01-17 13:43:28 -0800
commitfe166ed150248c815bfbbf63f82166a24f2394bf (patch)
tree59508a770c3b7e9ad5855841bc2d46544c8e5c96 /lib/chef/knife/ssh.rb
parent30ec971df95264b39e5e403c08b634d4708f5bee (diff)
parentb568c4d060765e75023f50f24d0a394ada5aed0b (diff)
downloadchef-ci-playground.tar.gz
Merge branch '10-stable' into integrate-chef-10-18-0ci-playground
Conflicts: .gitattributes chef-expander/Rakefile chef-expander/lib/chef/expander/version.rb chef-server-api/Rakefile chef-server-api/chef-server-api.gemspec chef-server-api/lib/chef-server-api/version.rb chef-server-webui/Rakefile chef-server-webui/chef-server-webui.gemspec chef-server-webui/lib/chef-server-webui/version.rb chef-server/Rakefile chef-server/lib/chef-server/version.rb chef-solr/lib/chef/solr/version.rb chef.gemspec chef/Rakefile chef/spec/support/platform_helpers.rb chef/spec/support/shared/functional/file_resource.rb chef/spec/unit/api_client_spec.rb chef/spec/unit/provider/directory_spec.rb ci/jenkins_run_tests.bat ci/jenkins_run_tests.sh distro/common/html/chef-client.8.html distro/common/html/chef-expander.8.html distro/common/html/chef-expanderctl.8.html distro/common/html/chef-server-webui.8.html distro/common/html/chef-server.8.html distro/common/html/chef-shell.1.html distro/common/html/chef-solo.8.html distro/common/html/chef-solr.8.html distro/common/html/knife-bootstrap.1.html distro/common/html/knife-client.1.html distro/common/html/knife-configure.1.html distro/common/html/knife-cookbook-site.1.html distro/common/html/knife-cookbook.1.html distro/common/html/knife-data-bag.1.html distro/common/html/knife-environment.1.html distro/common/html/knife-exec.1.html distro/common/html/knife-index.1.html distro/common/html/knife-node.1.html distro/common/html/knife-role.1.html distro/common/html/knife-search.1.html distro/common/html/knife-ssh.1.html distro/common/html/knife-status.1.html distro/common/html/knife-tag.1.html distro/common/html/knife.1.html distro/common/man/man1/chef-shell.1 distro/common/man/man1/knife-bootstrap.1 distro/common/man/man1/knife-client.1 distro/common/man/man1/knife-configure.1 distro/common/man/man1/knife-cookbook-site.1 distro/common/man/man1/knife-cookbook.1 distro/common/man/man1/knife-data-bag.1 distro/common/man/man1/knife-environment.1 distro/common/man/man1/knife-exec.1 distro/common/man/man1/knife-index.1 distro/common/man/man1/knife-node.1 distro/common/man/man1/knife-role.1 distro/common/man/man1/knife-search.1 distro/common/man/man1/knife-ssh.1 distro/common/man/man1/knife-status.1 distro/common/man/man1/knife-tag.1 distro/common/man/man1/knife.1 distro/common/man/man8/chef-client.8 distro/common/man/man8/chef-expander.8 distro/common/man/man8/chef-expanderctl.8 distro/common/man/man8/chef-server-webui.8 distro/common/man/man8/chef-server.8 distro/common/man/man8/chef-solo.8 distro/common/man/man8/chef-solr.8 lib/chef/api_client.rb lib/chef/rest.rb lib/chef/version.rb spec/functional/knife/ssh_spec.rb spec/functional/resource/cookbook_file_spec.rb spec/spec_helper.rb spec/stress/win32/security_spec.rb spec/support/shared/functional/securable_resource.rb spec/unit/config_spec.rb spec/unit/knife/ssh_spec.rb
Diffstat (limited to 'lib/chef/knife/ssh.rb')
-rw-r--r--lib/chef/knife/ssh.rb36
1 files changed, 24 insertions, 12 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb
index 481d97c1e7..100fee9fef 100644
--- a/lib/chef/knife/ssh.rb
+++ b/lib/chef/knife/ssh.rb
@@ -72,13 +72,13 @@ class Chef
:short => "-p PORT",
:long => "--ssh-port PORT",
:description => "The ssh port",
- :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
+ :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key.strip }
option :ssh_gateway,
:short => "-G GATEWAY",
:long => "--ssh-gateway GATEWAY",
:description => "The ssh gateway",
- :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key }
+ :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key.strip }
option :identity_file,
:short => "-i IDENTITY_FILE",
@@ -114,6 +114,22 @@ class Chef
@session ||= Net::SSH::Multi.start(:concurrent_connections => config[:concurrency], :on_error => ssh_error_handler)
end
+ def configure_gateway
+ config[:ssh_gateway] ||= Chef::Config[:knife][:ssh_gateway]
+ if config[:ssh_gateway]
+ gw_host, gw_user = config[:ssh_gateway].split('@').reverse
+ gw_host, gw_port = gw_host.split(':')
+ gw_opts = gw_port ? { :port => gw_port } : {}
+
+ session.via(gw_host, gw_user || config[:ssh_user], gw_opts)
+ end
+ rescue Net::SSH::AuthenticationFailed
+ user = gw_user || config[:ssh_user]
+ prompt = "Enter the password for #{user}@#{gw_host}: "
+ gw_opts.merge!(:password => prompt_for_password(prompt))
+ session.via(gw_host, user, gw_opts)
+ end
+
def configure_session
list = case config[:manual]
when true
@@ -154,15 +170,6 @@ class Chef
end
def session_from_list(list)
- config[:ssh_gateway] ||= Chef::Config[:knife][:ssh_gateway]
- if config[:ssh_gateway]
- gw_host, gw_user = config[:ssh_gateway].split('@').reverse
- gw_host, gw_port = gw_host.split(':')
- gw_opts = gw_port ? { :port => gw_port } : {}
-
- session.via(gw_host, gw_user || config[:ssh_user], gw_opts)
- end
-
list.each do |item|
Chef::Log.debug("Adding #{item}")
session_opts = {}
@@ -230,7 +237,11 @@ class Chef
end
def get_password
- @password ||= ui.ask("Enter your password: ") { |q| q.echo = false }
+ @password ||= prompt_for_password
+ end
+
+ def prompt_for_password(prompt = "Enter your password: ")
+ ui.ask(prompt) { |q| q.echo = false }
end
# Present the prompt and read a single line from the console. It also
@@ -416,6 +427,7 @@ class Chef
configure_attribute
configure_user
configure_identity_file
+ configure_gateway
configure_session
exit_status =