summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Connolly <patrick.c.connolly@gmail.com>2015-06-12 12:15:12 -0400
committerLamont Granquist <lamont@scriptkiddie.org>2015-10-24 17:54:55 -0700
commit0af405931884c3fa2cd30c54074e98fa78ea7235 (patch)
treef9ecd686862ce83dc26f3f21253858a38144aa3b
parentfa18670d7f97a83726ac45fb451271e7f070d574 (diff)
downloadchef-0af405931884c3fa2cd30c54074e98fa78ea7235.tar.gz
Allow user@hostname format for knife-bootstrap. [#3527]
* Fix unit test cases. * Ignore temporary spec testing files.
-rw-r--r--.gitignore3
-rw-r--r--lib/chef/knife/bootstrap.rb20
2 files changed, 19 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 39962d2f5f..953f58919f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,3 +43,6 @@ Vagrantfile
# Kitchen Tests Local Mode Data
kitchen-tests/nodes/*
+
+# Temporary files present during spec runs
+spec/data/test-dir
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index 93236225a2..767fe4297f 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -42,7 +42,7 @@ class Chef
Chef::Knife::Ssh.load_deps
end
- banner "knife bootstrap FQDN (options)"
+ banner "knife bootstrap [SSH_USER@]FQDN (options)"
option :ssh_user,
:short => "-x USERNAME",
@@ -256,13 +256,25 @@ class Chef
"chef-full"
end
+ def host_descriptor
+ Array(@name_args).first
+ end
+
# The server_name is the DNS or IP we are going to connect to, it is not necessarily
# the node name, the fqdn, or the hostname of the server. This is a public API hook
# which knife plugins use or inherit and override.
#
# @return [String] The DNS or IP that bootstrap will connect to
def server_name
- Array(@name_args).first
+ if host_descriptor
+ @server_name ||= host_descriptor.split('@').reverse[0]
+ end
+ end
+
+ def user_name
+ if host_descriptor
+ @user_name ||= host_descriptor.split('@').reverse[1]
+ end
end
def bootstrap_template
@@ -358,7 +370,7 @@ class Chef
if config[:ssh_password]
raise
else
- ui.info("Failed to authenticate #{config[:ssh_user]} - trying password auth")
+ ui.info("Failed to authenticate #{knife_ssh.config[:ssh_user]} - trying password auth")
knife_ssh_with_password_auth.run
end
end
@@ -389,7 +401,7 @@ class Chef
ssh = Chef::Knife::Ssh.new
ssh.ui = ui
ssh.name_args = [ server_name, ssh_command ]
- ssh.config[:ssh_user] = config[:ssh_user]
+ ssh.config[:ssh_user] = user_name || config[:ssh_user]
ssh.config[:ssh_password] = config[:ssh_password]
ssh.config[:ssh_port] = config[:ssh_port]
ssh.config[:ssh_gateway] = config[:ssh_gateway]