From 02a351841e0331604dc66e555c1146704cbba435 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 19 Nov 2015 16:32:43 -0800 Subject: [PATCH] Use an array instead of map --- lib/vagrant/util/ssh.rb | 6 +++--- plugins/communicators/ssh/communicator.rb | 18 +----------------- .../source/v2/vagrantfile/ssh_settings.html.md | 9 +++++++-- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/vagrant/util/ssh.rb b/lib/vagrant/util/ssh.rb index 5f3876ce9..f5d6b916d 100644 --- a/lib/vagrant/util/ssh.rb +++ b/lib/vagrant/util/ssh.rb @@ -139,7 +139,7 @@ module Vagrant end if ssh_info[:forward_env] - command_options += ["-o", "SendEnv=" + ssh_info[:forward_env].keys().join(" ")] + command_options += ["-o", "SendEnv=#{ssh_info[:forward_env].join(" ")}"] end # Configurables -- extra_args should always be last due to the way the @@ -179,8 +179,8 @@ module Vagrant # Forward configured environment variables. if ssh_info[:forward_env] - ssh_info[:forward_env].each do |host_var, guest_var| - process.environment[guest_var] = ENV[guest_var] + ssh_info[:forward_env].each do |key| + process.environment[key] = ENV[key] end end diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index 86999502b..19b2306b1 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -328,28 +328,17 @@ module VagrantPlugins auth_methods << "publickey" if ssh_info[:private_key_path] auth_methods << "password" if ssh_info[:password] - # Build the environment - env_revert = {} - send_env_array = nil - if ssh_info[:forward_agent] - send_env_array = ssh_info[:forward_env].values() - ssh_info[:forward_env].each do |host_var, guest_var| - env_revert[guest_var] = ENV[guest_var] - ENV[guest_var] = ENV[host_var] - end - end - # Build the options we'll use to initiate the connection via Net::SSH common_connect_opts = { auth_methods: auth_methods, config: false, forward_agent: ssh_info[:forward_agent], + forward_env: ssh_info[:forward_env], keys: ssh_info[:private_key_path], keys_only: true, paranoid: false, password: ssh_info[:password], port: ssh_info[:port], - send_env: send_env_array, timeout: 15, user_known_hosts_file: [], verbose: :debug, @@ -442,11 +431,6 @@ module VagrantPlugins # This is raised if a private key type that Net-SSH doesn't support # is used. Show a nicer error. raise Vagrant::Errors::SSHKeyTypeNotSupported - ensure - # TODO: will this leak? - env_revert.each do |guest_var, guest_value| - ENV[guest_var] = guest_value - end end @connection = connection diff --git a/website/docs/source/v2/vagrantfile/ssh_settings.html.md b/website/docs/source/v2/vagrantfile/ssh_settings.html.md index 67bfb7936..5db92e034 100644 --- a/website/docs/source/v2/vagrantfile/ssh_settings.html.md +++ b/website/docs/source/v2/vagrantfile/ssh_settings.html.md @@ -67,8 +67,13 @@ is enabled. Defaults to false.
-`config.ssh.forward_env` - A hash of host environment variable names to guest -environment variable names. +`config.ssh.forward_env` - An array of host environment variables to forward to +the guest. If you are familiar with OpenSSH, this corresponds to the `SendEnv` +paramter. + +```ruby +config.ssh.forward_env = ["CUSTOM_VAR"] +```