lib/chef/knife/ssh.rb in chef-10.14.0.beta.3 vs lib/chef/knife/ssh.rb in chef-10.14.0.rc.0

- old
+ new

@@ -77,11 +77,11 @@ option :ssh_gateway, :short => "-G GATEWAY", :long => "--ssh-gateway GATEWAY", :description => "The ssh gateway", - :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gatewa] = key } + :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key } option :identity_file, :short => "-i IDENTITY_FILE", :long => "--identity-file IDENTITY_FILE", :description => "The SSH identity file used for authentication" @@ -122,11 +122,17 @@ when false r = Array.new q = Chef::Search::Query.new @action_nodes = q.search(:node, @name_args[0])[0] @action_nodes.each do |item| - i = format_for_display(item)[config[:attribute]] + # if a command line attribute was not passed, and we have a cloud public_hostname, use that. + # see #configure_attribute for the source of config[:attribute] and config[:override_attribute] + if !config[:override_attribute] && item[:cloud] and item[:cloud][:public_hostname] + i = format_for_display(item)[:cloud][:public_hostname] + else + i = format_for_display(item)[config[:attribute]] + end r.push(i) unless i.nil? end r end (ui.fatal("No nodes returned from search!"); exit 10) if list.length == 0 @@ -332,9 +338,15 @@ Appscript.app('Terminal').do_script(cmd, :in => window.tabs[tab_number + 1].get) end end def configure_attribute + # Setting 'knife[:ssh_attribute] = "foo"' in knife.rb => Chef::Config[:knife][:ssh_attribute] == 'foo' + # Running 'knife ssh -a foo' => both Chef::Config[:knife][:ssh_attribute] && config[:attribute] == foo + # Thus we can differentiate between a config file value and a command line override at this point by checking config[:attribute] + # We can tell here if fqdn was passed from the command line, rather than being the default, by checking config[:attribute] + # However, after here, we cannot tell these things, so we must preserve config[:attribute] + config[:override_attribute] = config[:attribute] config[:attribute] = (Chef::Config[:knife][:ssh_attribute] || config[:attribute] || "fqdn").strip end