Flesh out `:config` support.

Also noticed whilst testing that if the `ProxyCommand` uses `%r`, then
it fails with `unable to find remote user`, so added support for
`config.ssh.remote_user` aswell
This commit is contained in:
Gavin Williams 2018-09-27 15:22:51 +01:00 committed by Chris Roberts
parent 87e38a0bed
commit 122ef7307c
4 changed files with 18 additions and 0 deletions

View File

@ -452,9 +452,11 @@ module Vagrant
info[:keys_only] ||= @config.ssh.default.keys_only
info[:verify_host_key] ||= @config.ssh.default.verify_host_key
info[:username] ||= @config.ssh.default.username
info[:remote_user] ||= @config.ssh.default.remote_user
info[:compression] ||= @config.ssh.default.compression
info[:dsa_authentication] ||= @config.ssh.default.dsa_authentication
info[:extra_args] ||= @config.ssh.default.extra_args
info[:config] ||= @config.ssh.default.config
# We set overrides if they are set. These take precedence over
# provider-returned data.
@ -466,7 +468,9 @@ module Vagrant
info[:dsa_authentication] = @config.ssh.dsa_authentication
info[:username] = @config.ssh.username if @config.ssh.username
info[:password] = @config.ssh.password if @config.ssh.password
info[:remote_user] = @config.ssh.remote_user if @config.ssh.remote_user
info[:extra_args] = @config.ssh.extra_args if @config.ssh.extra_args
info[:config] = @config.ssh.config if @config.ssh.config
# We also set some fields that are purely controlled by Vagrant
info[:forward_agent] = @config.ssh.forward_agent

View File

@ -55,6 +55,8 @@ module VagrantPlugins
proxy_command: ssh_info[:proxy_command],
ssh_command: ssh_info[:ssh_command],
forward_env: ssh_info[:forward_env],
config: ssh_info[:config],
remote_user: ssh_info[:remote_user],
}
# Render the template and output directly to STDOUT

View File

@ -418,6 +418,10 @@ module VagrantPlugins
connect_opts[:config] = ssh_info[:config]
end
if ssh_info[:remote_user]
connect_opts[:remote_user] = ssh_info[:remote_user]
end
@logger.info("Attempting to connect to SSH...")
@logger.info(" - Host: #{ssh_info[:host]}")
@logger.info(" - Port: #{ssh_info[:port]}")

View File

@ -3,6 +3,7 @@ module VagrantPlugins
class SSHConnectConfig < Vagrant.plugin("2", :config)
attr_accessor :host
attr_accessor :port
attr_accessor :config
attr_accessor :private_key_path
attr_accessor :username
attr_accessor :password
@ -13,10 +14,12 @@ module VagrantPlugins
attr_accessor :compression
attr_accessor :dsa_authentication
attr_accessor :extra_args
attr_accessor :remote_user
def initialize
@host = UNSET_VALUE
@port = UNSET_VALUE
@config = UNSET_VALUE
@private_key_path = UNSET_VALUE
@username = UNSET_VALUE
@password = UNSET_VALUE
@ -27,6 +30,7 @@ module VagrantPlugins
@compression = UNSET_VALUE
@dsa_authentication = UNSET_VALUE
@extra_args = UNSET_VALUE
@remote_user = UNSET_VALUE
end
def finalize!
@ -42,6 +46,7 @@ module VagrantPlugins
@compression = true if @compression == UNSET_VALUE
@dsa_authentication = true if @dsa_authentication == UNSET_VALUE
@extra_args = nil if @extra_args == UNSET_VALUE
@remote_user = nil if @remote_user == UNSET_VALUE
if @private_key_path && !@private_key_path.is_a?(Array)
@private_key_path = [@private_key_path]
@ -51,6 +56,9 @@ module VagrantPlugins
@verify_host_key = @paranoid
end
# Default to not loading system ssh_config file
@config = false if @config == UNSET_VALUE
# Values for verify_host_key changed in 5.0.0 of net-ssh. If old value
# detected, update with new value
case @verify_host_key