Troubleshooting Vagrant Manager: Common Issues and Fixes

Step-by-Step: Setting Up a Multi-VM Stack with Vagrant Manager

This guide walks through building a reproducible multi-VM development stack using Vagrant Manager. It assumes basic familiarity with Vagrant and VirtualBox (or another provider). Final result: a Vagrantfile and supporting configs that bring up multiple VMs (app, database, load balancer), networked and provisioned for development.

1. What you’ll get

  • Three VMs: app (web), db (Postgres), lb (nginx load balancer)
  • Private network addressing and hostname resolution
  • Shared synced folder for app code
  • Simple provisioning with shell scripts (replaceable with Ansible/Chef)
  • Commands to bring the full stack up, halt, and reprovision

2. Prerequisites

  • Vagrant installed
  • VirtualBox (or another supported provider)
  • Vagrant Manager (assumed installed to manage multiple VMs visually — configuration is standard Vagrant)
  • Basic shell access (macOS/Linux/WSL/Windows PowerShell)

3. Project structure

Create a project folder with this layout:

  • Vagrantfile
  • provision/
    • app.sh
    • db.sh
    • lb.sh
  • www/ (your app code — will be synced)

4. Vagrantfile (multi-VM configuration)

Create a Vagrantfile in the project root. This example is provider-agnostic and uses a private network and hostnames.

ruby

Vagrant.configure(“2”) do |config|# Common settings config.vm.box = “ubuntu/focal64” config.vm.synced_folder “./www”, “/vagrant/www”, owner: “vagrant”, group: “vagrant”

# App VM config.vm.define “app” do |app|

app.vm.hostname = "app.local" app.vm.network "private_network", ip: "192.168.56.10" app.vm.provider "virtualbox" do |vb|   vb.memory = 1024   vb.cpus = 1 end app.vm.provision "shell", path: "provision/app.sh" 

end

# DB VM config.vm.define “db” do |db|

db.vm.hostname = "db.local" db.vm.network "private_network", ip: "192.168.56.11" db.vm.provider "virtualbox" do |vb|   vb.memory = 512   vb.cpus = 1 end db.vm.provision "shell", path: "provision/db.sh" 

end

# Load balancer VM config.vm.define “lb” do |lb|

lb.vm.hostname = "lb.local" lb.vm.network "private_network", ip: "192.168.56.12" lb.vm.provider "virtualbox" do |vb|   vb.memory = 512   vb.cpus = 1 end lb.vm.provision "shell", path: "provision/lb.sh" 

end end

5. Provisioning scripts

Place simple shell scripts in provision/ to install and configure services. Replace with more robust tooling for production-like setups.

provision/app.sh: “`bash #!/bin/bash set -e

Update and install essentials

apt-get update -y apt-get install -y nginx git build-essential

Example: serve static content from /vagrant/www

rm -f /etc/nginx/sites-enabled/default cat > /etc

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *