Permalink
Browse files

Always include the port (defaulted to 22) in the ssh-keyscan command.…

… Add port as a param to known_hosts LWRP.
  • Loading branch information...
1 parent 51c3353 commit a9830e3de3c724f112c5ec1e640b0457fd92c5da @markolson committed Dec 9, 2013
Showing with 4 additions and 2 deletions.
  1. +3 −2 providers/known_hosts.rb
  2. +1 −0 resources/known_hosts.rb
View
@@ -5,11 +5,12 @@
ssh_user = new_resource.user || 'root'
known_hosts_path = default_or_user_path(node['ssh']['known_hosts_path'], ssh_user)
host, port = new_resource.host.split(':')
+ # set the port to the default (22) if it wasn't already set
+ port = new_resource.port unless port
key = new_resource.key
if key.nil?
- port_arg = port.nil? ? '' : "-p #{port}"
- results = `ssh-keyscan #{new_resource.hashed ? '-H ' : ''} #{port_arg} #{Shellwords.escape(host)}`
+ results = `ssh-keyscan #{new_resource.hashed ? '-H ' : ''} -p #{port.to_i} #{Shellwords.escape(host)}`
Chef::Application.fatal! results.strip if key =~ /getaddrinfo/
key = results.strip
end
View
@@ -2,6 +2,7 @@
default_action :add
attribute :host, :kind_of => String, :name_attribute => true
+attribute :port, :kind_of => Integer, :default => 22
attribute :hashed, :kind_of => [TrueClass, FalseClass], :default => TrueClass
attribute :key, :kind_of => String
attribute :user, :kind_of => String

0 comments on commit a9830e3

Please sign in to comment.