Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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))
like image 211
Nathan Avatar asked Apr 27 '12 15:04

Nathan


2 Answers

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.)

like image 73
oseiskar Avatar answered Nov 15 '22 21:11

oseiskar


I figured it out. In case others care to know:

  1. I created a separate folder and did the whole Vagrant init there.
  2. I configured the Vagrant file to use a bridged network.
  3. I signed into my vagrant VM ($ vagrant ssh) and ran ifconfig to get my IP address.
  4. I added that IP address to my Capistrano deploy file.
  5. I passed along vagrants ssh info to my local configs: vagrant ssh-config >> ~/.ssh/config
  6. I ran my deploy, when prompted for the SSH password, I used vagrant

It worked.

like image 23
Nathan Avatar answered Nov 15 '22 23:11

Nathan