lib/vagrant/machine.rb
# This returns the SSH info for accessing this machine. This SSH info
# is queried from the underlying provider. This method returns `nil` if
# the machine is not ready for SSH communication.
#
# The structure of the resulting hash is guaranteed to contain the
# following structure, although it may return other keys as well
# not documented here:
#
#     {
#       :host => "1.2.3.4",
#       :port => "22",
#       :username => "mitchellh",
#       :private_key_path => "/path/to/my/key"
#     }
#
# Note that Vagrant makes no guarantee that this info works or is
# correct. This is simply the data that the provider gives us or that
# is configured via a Vagrantfile. It is still possible after this
# point when attempting to connect via SSH to get authentication
# errors.
#
# @return [Hash] SSH information.
This returns the SSH info for accessing this machine. This SSH info
is queried from the underlying provider. This method returns `nil` if
the machine is not ready for SSH communication.

The structure of the resulting hash is guaranteed to contain the
following structure, although it may return other keys as well
not documented here.



Note that Vagrant makes no guarantee that this info works or is
correct. This is simply the data that the provider gives us or that
is configured via a Vagrantfile. It is still possible after this
point when attempting to connect via SSH to get authentication
errors.
This returns the SSH info for accessing this machine . This SSH info is queried from the underlying provider . This method returns ` nil ` if the machine is not ready for SSH communication . The structure of the resulting hash is guaranteed to contain the following structure although it may return other keys as well not documented here . Note that Vagrant makes no guarantee that this info works or is correct . This is simply the data that the provider gives us or that is configured via a Vagrantfile . It is still possible after this point when attempting to connect via SSH to get authentication errors .
def ssh_info
      info = @provider.ssh_info
      return nil if info.nil?
      info.dup.each do |key, value|
        info.delete(key) if value.nil?
      end
      info[:host] ||= @config.ssh.default.host
      info[:port] ||= @config.ssh.default.port
      info[:private_key_path] ||= @config.ssh.default.private_key_path
      info[:username] ||= @config.ssh.default.username
      info[:host] = @config.ssh.host if @config.ssh.host
      info[:port] = @config.ssh.port if @config.ssh.port
      info[:username] = @config.ssh.username if @config.ssh.username
      info[:password] = @config.ssh.password if @config.ssh.password
      info[:forward_agent] = @config.ssh.forward_agent
      info[:forward_x11]   = @config.ssh.forward_x11
      info[:proxy_command] = @config.ssh.proxy_command if @config.ssh.proxy_command
      if !info[:private_key_path] && !info[:password]
        if @config.ssh.private_key_path
          info[:private_key_path] = @config.ssh.private_key_path
        else
          info[:private_key_path] = @env.default_private_key_path
        end
      end
      data_private_key = @data_dir.join("private_key")
      if data_private_key.file?
        info[:private_key_path] = [data_private_key.to_s]
      end
      info[:private_key_path] ||= []
      if !info[:private_key_path].is_a?(Array)
        info[:private_key_path] = [info[:private_key_path]]
      end
      info[:private_key_path].map! do |path|
        File.expand_path(path, @env.root_path)
      end
      info
    end
def ssh_info info = @provider . ssh_info return nil if info . nil? info . dup . each do | key , value | info . delete ( key ) if value . nil? end info [ :host ] ||= @config . ssh . default . host info [ :port ] ||= @config . ssh . default . port info [ :private_key_path ] ||= @config . ssh . default . private_key_path info [ :username ] ||= @config . ssh . default . username info [ :host ] = @config . ssh . host if @config . ssh . host info [ :port ] = @config . ssh . port if @config . ssh . port info [ :username ] = @config . ssh . username if @config . ssh . username info [ :password ] = @config . ssh . password if @config . ssh . password info [ :forward_agent ] = @config . ssh . forward_agent info [ :forward_x11 ] = @config . ssh . forward_x11 info [ :proxy_command ] = @config . ssh . proxy_command if @config . ssh . proxy_command if ! info [ :private_key_path ] && ! info [ :password ] if @config . ssh . private_key_path info [ :private_key_path ] = @config . ssh . private_key_path else info [ :private_key_path ] = @env . default_private_key_path end end data_private_key = @data_dir . join ( "private_key" ) if data_private_key . file? info [ :private_key_path ] = [ data_private_key . to_s ] end info [ :private_key_path ] ||= [ ] if ! info [ :private_key_path ] . is_a? ( Array ) info [ :private_key_path ] = [ info [ :private_key_path ] ] end info [ :private_key_path ] . map! do | path | File . expand_path ( path , @env . root_path ) end info end
This returns the SSH info for accessing this machine.
This returns the SSH info for accessing this machine .
# First, ask the provider for their information. If the provider # returns nil, then the machine is simply not ready for SSH, and # we return nil as well. # Delete out the nil entries. # We set the defaults # We set overrides if they are set. These take precedence over # provider-returned data. # We also set some fields that are purely controlled by Varant # Add in provided proxy command config # Set the private key path. If a specific private key is given in # the Vagrantfile we set that. Otherwise, we use the default (insecure) # private key, but only if the provider didn't give us one. # If we have a private key in our data dir, then use that # Setup the keys # Expand the private key path relative to the root path # Return the final compiled SSH info data
None
Hash