diff --git a/bin/vagrant-ssh-config b/bin/vagrant-ssh-config index f754a1c2d..d12445ce6 100755 --- a/bin/vagrant-ssh-config +++ b/bin/vagrant-ssh-config @@ -22,7 +22,9 @@ to the current environment. EOS + opt :host, "the host key for the entry", :type => :string + run do |command| - Vagrant::Commands.execute(:ssh_config) + Vagrant::Commands.execute(:ssh_config, command.opts) end end diff --git a/lib/vagrant/commands.rb b/lib/vagrant/commands.rb index 77b954a44..171143221 100644 --- a/lib/vagrant/commands.rb +++ b/lib/vagrant/commands.rb @@ -63,10 +63,10 @@ module Vagrant # Outputs a valid entry for .ssh/config which can be used to connect # to this environment. - def ssh_config + def ssh_config(opts={}) env.require_root_path puts TemplateRenderer.render("ssh_config", { - :host_key => "vagrant", + :host_key => opts[:host] || "vagrant", :ssh_user => env.config.ssh.username, :ssh_port => env.ssh.port, :private_key_path => env.config.ssh.private_key_path diff --git a/test/vagrant/commands_test.rb b/test/vagrant/commands_test.rb index 8267f5865..9c1cee384 100644 --- a/test/vagrant/commands_test.rb +++ b/test/vagrant/commands_test.rb @@ -116,6 +116,13 @@ class CommandsTest < Test::Unit::TestCase @env.stubs(:require_root_path) @commands.stubs(:puts) + + @data = { + :host_key => "vagrant", + :ssh_user => @env.config.ssh.username, + :ssh_port => @env.ssh.port, + :private_key_path => @env.config.ssh.private_key_path + } end should "require root path" do @@ -125,16 +132,18 @@ class CommandsTest < Test::Unit::TestCase should "output rendered template" do result = mock("result") - Vagrant::Util::TemplateRenderer.expects(:render).with("ssh_config", { - :host_key => "vagrant", - :ssh_user => @env.config.ssh.username, - :ssh_port => @env.ssh.port, - :private_key_path => @env.config.ssh.private_key_path - }).returns(result) + Vagrant::Util::TemplateRenderer.expects(:render).with("ssh_config", @data).returns(result) @commands.expects(:puts).with(result).once @commands.ssh_config end + + should "render with the given host name if given" do + opts = { :host => "foo" } + @data[:host_key] = opts[:host] + Vagrant::Util::TemplateRenderer.expects(:render).with("ssh_config", @data) + @commands.ssh_config(opts) + end end context "suspend" do