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

3

21

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))
Luther answered 27/4, 2012 at 15:33 Comment(0)
L
14

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.

Luther answered 27/4, 2012 at 15:57 Comment(1)
You could also use hostonly networking. Two advantages. One, can assign ip address, so don't need to look it up everytime. Two, machines don't have access to the network at large. Otherwise instructions would be same.Cathern
A
19

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

Airtoair answered 16/2, 2013 at 13:12 Comment(0)
L
14

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.

Luther answered 27/4, 2012 at 15:57 Comment(1)
You could also use hostonly networking. Two advantages. One, can assign ip address, so don't need to look it up everytime. Two, machines don't have access to the network at large. Otherwise instructions would be same.Cathern
C
0

I had the same issue and thanks to the solution of @Nathan I could fix the issue. I have a different release setup. Was trying to test release a ruby project in my VM with Capistrano, but had a authentication error on user@localhost. SSH user@localhost worked fine.

My build setup is Oracle Virtual Box with Ubuntu 22.04 LTS installed as VM. To connect with SSH to your VM with Capistrano you have to do the following:

  1. Go to your settings of the VM e.g. ubuntu 22.04 LTS;
  2. Go to Network and set Attached to Bridged Adapter
  3. Set Name to your local network: mine was wlp4s0
  4. Set Promisecuous Mode to Allow All;
  5. Now restart your Ubuntu VM and check your ip under inet by running ifconfig;
  6. Try to connect to your server with SSH to check if it still works ssh user_for_cap@ip_address
  7. Put that ip as config in your cap file and connect with ssh_options like: server 'ip_address', user: 'user_for_cap', roles: %w[app], port: 22

It Worked!

Culprit answered 21/9, 2022 at 11:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.