Is there a way to deploy into a vagrant VM using Capistrano?

Nathan picture Nathan · Apr 27, 2012 · Viewed 7.3k times · Source

I'd like to setup a vagrant instance outside of my project directory. Is there a way to deploy rails into the vagrant VM with capistrano as I would to my real production host?

I'm trying to use server as "localhost" but I get:

connection failed for: localhost (Errno::ECONNREFUSED: Connection refused - connect(2))

Answer

oseiskar picture oseiskar · Feb 16, 2013

You can also feed Vagrant's SSH options to Capistrano (most of the :ssh_options go directly to Net::SSH, http://net-ssh.github.com/ssh/v1/chapter-2.html, see "Options") so there is no need to mess your real ~/.ssh/config

set :user, 'vagrant'
set :ssh_options, {port: 2222, keys: ['~/.vagrant.d/insecure_private_key']}

role :web, "localhost" 
...

(Of course, you shouldn't really be using the insecure_private_key or the default root/vagrant passwords unless properly firewalled, but the principle remains the same.)