Skip to content

Instantly share code, notes, and snippets.

@viettranx
Created August 27, 2022 13:00
Show Gist options
  • Save viettranx/97a1ddceb78a7933e654a975b606b03b to your computer and use it in GitHub Desktop.
Save viettranx/97a1ddceb78a7933e654a975b606b03b to your computer and use it in GitHub Desktop.
Simple Vagrant File - Create a VM with Ubuntu OS
# -*- mode: ruby -*-
# vi: set ft=ruby :
$install_docker_script = <<SCRIPT
echo "Installing dependencies ..."
sudo apt-get update
echo Installing Docker...
curl -sSL https://get.docker.com/ | sh
sudo usermod -aG docker vagrant
SCRIPT
BOX_NAME = "alvistack/ubuntu-18.04"
MEMORY = "512"
MACHINES = 1
IP = "192.168.56.1"
CPUS = 2
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
#Common setup
config.vm.box = BOX_NAME
config.vm.synced_folder ".", "/vagrant"
config.vm.provision "shell",inline: $install_docker_script, privileged: true
config.vm.provider "virtualbox" do |vb|
vb.memory = MEMORY
vb.cpus = CPUS
end
(1..MACHINES).each do |i|
config.vm.define "machine#{i}" do |manager|
manager.vm.network :private_network, ip: "#{IP}#{i}"
manager.vm.hostname = "machine#{i}"
if i == 1
manager.vm.network :forwarded_port, guest: 80, host: 80
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment