diff --git a/CHANGELOG.md b/CHANGELOG.md index bc6ed8bec..64295274b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ by shortcut. [GH-367] - Arbitrary mount options can be passed with `:extra` to any shared folders. [GH-551] + - Options passed after a `--` to `vagrant ssh` are now passed directly to + `ssh`. [GH-554] - Removed Thor as a dependency for the command line interfaces. This resulted in general speed increases across all command line commands. - Linux uses `shutdown -h` instead of `halt` to hopefully more consistently diff --git a/lib/vagrant/command/ssh.rb b/lib/vagrant/command/ssh.rb index acbe41deb..e49e5446a 100644 --- a/lib/vagrant/command/ssh.rb +++ b/lib/vagrant/command/ssh.rb @@ -7,7 +7,7 @@ module Vagrant options = {} opts = OptionParser.new do |opts| - opts.banner = "Usage: vagrant ssh [vm-name] [-c command]" + opts.banner = "Usage: vagrant ssh [vm-name] [-c command] [-- extra ssh args]" opts.separator "" @@ -19,9 +19,22 @@ module Vagrant end end + # Parse the options and return if we don't have any target. argv = parse_options(opts) return if !argv + # Parse out the extra args to send to SSH, which is everything + # after the "--" + ssh_args = ARGV.drop_while { |i| i != "--" } + ssh_args = ssh_args[1..-1] + options[:ssh_args] = ssh_args + + # If the remaining arguments ARE the SSH arguments, then just + # clear it out. This happens because optparse returns what is + # after the "--" as remaining ARGV, and Vagrant can think it is + # a multi-vm name (wrong!) + argv = [] if argv == ssh_args + # Execute the actual SSH with_target_vms(argv[0], true) do |vm| # Basic checks that are required for proper SSH @@ -32,7 +45,12 @@ module Vagrant if options[:command] ssh_execute(vm, options[:command]) else - ssh_connect(vm, { :plain_mode => options[:plain_mode] }) + opts = { + :plain_mode => options[:plain_mode], + :extra_args => options[:ssh_args] + } + + ssh_connect(vm, opts) end end end diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 800661e5f..1201711c2 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -79,6 +79,9 @@ module Vagrant command_options << "-i #{options[:private_key_path]}" if !plain_mode command_options << "-o ForwardAgent=yes" if ssh_info[:forward_agent] + # If there are extra options, then we append those + command_options.concat(opts[:extra_args]) if opts[:extra_args] + if ssh_info[:forward_x11] # Both are required so that no warnings are shown regarding X11 command_options << "-o ForwardX11=yes"