lib/chef/knife/ssh.rb in chef-0.10.2 vs lib/chef/knife/ssh.rb in chef-0.10.4.rc.1
- old
+ new
@@ -147,13 +147,12 @@
def print_data(host, data)
if data =~ /\n/
data.split(/\n/).each { |d| print_data(host, d) }
else
padding = @longest - host.length
- print ui.color(host, :cyan)
- padding.downto(0) { print " " }
- puts data
+ str = ui.color(host, :cyan) + (" " * (padding + 1)) + data
+ ui.msg(str)
end
end
def ssh_command(command, subsession=nil)
subsession ||= session
@@ -239,21 +238,23 @@
tf.puts("caption always '%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<'")
tf.puts("hardstatus alwayslastline 'knife ssh #{@name_args[0]}'")
window = 0
session.servers_for.each do |server|
tf.print("screen -t \"#{server.host}\" #{window} ssh ")
+ tf.print("-i #{config[:identity_file]} ") if config[:identity_file]
server.user ? tf.puts("#{server.user}@#{server.host}") : tf.puts(server.host)
window += 1
end
tf.close
exec("screen -c #{tf.path}")
end
def tmux
ssh_dest = lambda do |server|
+ identity = "-i #{config[:identity_file]} " if config[:identity_file]
prefix = server.user ? "#{server.user}@" : ""
- "'ssh #{prefix}#{server.host}'"
+ "'ssh #{identity}#{prefix}#{server.host}'"
end
new_window_cmds = lambda do
if session.servers_for.size > 1
[""] + session.servers_for[1..-1].map do |server|
@@ -298,14 +299,34 @@
cmd = "unset PROMPT_COMMAND; echo -e \"\\033]0;#{server.host}\\007\"; ssh #{server.user ? "#{server.user}@#{server.host}" : server.host}"
Appscript.app('Terminal').do_script(cmd, :in => window.tabs[tab_number + 1].get)
end
end
+ def configure_attribute
+ config[:attribute] = (config[:attribute] ||
+ Chef::Config[:knife][:ssh_attribute] ||
+ "fqdn").strip
+ end
+
+ def configure_user
+ config[:ssh_user] = (config[:ssh_user] ||
+ Chef::Config[:knife][:ssh_user])
+ config[:ssh_user].strip! unless config[:ssh_user].nil?
+ end
+
+ def configure_identity_file
+ config[:identity_file] = (config[:identity_file] || Chef::Config[:knife][:ssh_identity_file])
+ config[:identity_file].strip! unless config[:identity_file].nil?
+ end
+
def run
extend Chef::Mixin::Command
@longest = 0
+ configure_attribute
+ configure_user
+ configure_identity_file
configure_session
case @name_args[1]
when "interactive"
interactive