Skip to content

Commit 56d0496

Browse files
committed
Adding ssh user support
1 parent 9308b58 commit 56d0496

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

chef/lib/chef/knife/ssh.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ class Ssh < Knife
4444
:description => "QUERY is a space separated list of servers",
4545
:default => false
4646

47+
option :ssh_user,
48+
:short => "-x USERNAME",
49+
:long => "--ssh-user USERNAME",
50+
:description => "The ssh username"
51+
4752
def session
4853
@session ||= Net::SSH::Multi.start(:concurrent_connections => config[:concurrency])
4954
end
5055

51-
5256
def h
5357
@highline ||= HighLine.new
5458
end
@@ -71,7 +75,7 @@ def configure_session
7175
def session_from_list(list)
7276
list.each do |item|
7377
Chef::Log.debug("Adding #{item}")
74-
session.use item
78+
session.use config[:ssh_user] ? "#{config[:ssh_user]}@#{item}" : item
7579
@longest = item.length if item.length > @longest
7680
end
7781
session
@@ -173,8 +177,9 @@ def screen
173177
tf.puts("caption always '%w'")
174178
tf.puts("hardstatus alwayslastline 'knife ssh #{@name_args[0]}'")
175179
window = 0
176-
session.servers_for.collect { |s| s.host }.each do |server|
177-
tf.puts("screen -t \"#{server}\" #{window} ssh #{server}")
180+
session.servers_for.each do |server|
181+
tf.print("screen -t \"#{server.host}\" #{window} ssh ")
182+
server.user ? tf.puts("#{server.user}@#{server.host}") : tf.puts(server.host)
178183
window += 1
179184
end
180185
tf.close

0 commit comments

Comments
 (0)