skip to content
Hugo

Set up 3 VMs ubuntu with vagrant

/ 1 min read

Table of Contents

Summary

In this post I will show you how we can set up 3 VMs with vagrant

Getting started

Setting dependencies

Verify vagrant

Terminal window
$ vagrant -v

In this post version of grant is Vagrant 2.2.18 and Virtual Box is 6.1.26

Solution

  1. Go to working directory
Terminal window
$ cd ~/ && mkdir ubuntu-vm && cd ubuntu-vm
  1. Init Vagrant config
Terminal window
$ vagrant init
  1. Update Vagrant config

Because I will set up 3 VMs ubuntu so you can follow the config file like that:

Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: <<-SHELL
apt-get update
SHELL
(1..3).each do |i|
config.vm.define "machine#{i}" do |machine|
machine.vm.box = "hashicorp/bionic64"
machine.vm.box_version = "1.0.282"
machine.vm.network "private_network", ip: "192.168.0.10#{i}"
machine.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.cpus = 1
end
end
end
end

You can read more vagrant docs and some tips and tricks

  1. Start VM with vagrant cli
Terminal window
$ vagrant up
  1. Verify

After vagrant up you can verify by access to VM. default user and password to access VM are vagrant

Terminal window
$ ssh vagrant@192.168.0.101
$ ssh vagrant@192.168.0.102
$ ssh vagrant@192.168.0.103