Using vagrant to setup multiple virtual machine

This is another post about using Vagrant to set up development environment in your local machine. Please consider to read previous post about setup vagrant for one VM.

My config to setup 2 virtual machine in a project do |config|

  config.vm.define :web do |web_config| = "debian"
    web_config.vm.share_folder "SERVER", "/SERVER", SERVER_PATH
    web_config.vm.share_folder "DATA", "/DEVELOPMENT", DEVELOPMENT_PATH
    web_config.vm.forward_port 22, 2222
    web_config.vm.forward_port 80, 4567 :hostonly, ""
    web_config.vm.customize ["modifyvm", :id, "--memory", 512]

  config.vm.define :sentry do |sentry_config| = "debian"
    sentry_config.vm.share_folder "SERVER", "/SERVER", SERVER_PATH
    sentry_config.vm.share_folder "DATA", "/DEVELOPMENT", DEVELOPMENT_PATH
    sentry_config.vm.forward_port 22, 2223 :hostonly, ""
    sentry_config.vm.customize ["modifyvm", :id, "--memory", 512]

This setup will create 2 Virtual Machine, one is “web” have ipaddress “” and another is “sentry” with ipaddress is “”.

But now, if you using vagrant up, this will start import debian box to create two fresh new Virtual Machines. This is really problems if you already setup some virtual machines, and just want to associate that machine with vagrant.

To do this, look at your .vagrant file in same folder of Vagrantfile. The format of file is

{"active":{"default":"machine uuid"}}

Change it to format

{"active":{"web":"<uuid1>", "sentry":"<uuid2>"}}

To get uuid of virtual machine, using VBoxManage command

$> VBoxManage list vms
# using VBoxManage, you also can control virtual machine
$> VBoxManage controlvm <vm_uuid> start|poweroff|reset
# for more useful command, try to test VBoxManage
# try and failed is best way to learn :-)

Kien Nguyen Trung

A father, husband and Elixir lover.

Ho Chi Minh, Vietnam