To create the virtual machines (VM) of our project we will use Vagrant with a file Vagrantfile, where we define all the necessary configurations.
At first, we will use the option –provision to lift the machine. This ensures that all the scripts and settings we put in the Vagrantfile are applied correctly during the initial creation of the MV.
Once the machine is created and configured, no need to use again –provision every time we launch it, since the settings only need to be applied the first time.
Vagrant.configure("2") do |config|
# DNS
config.vm.define "DNS" do |dns|
dns.vm.box = "rockyinfo"
dns.vm.hostname = "dns"
dns.vm.network "public_network", type: "dhcp"
dns.vm.provision "shell", inline: <<-SHELL
echo "Configuring DNS server"
SHELL
end
# DHCP
config.vm.define "DHCP" do |dhcp|
dhcp.vm.box = "rockyinfo"
dhcp.vm.hostname = "dhcp"
dhcp.vm.network "public_network", type: "dhcp"
dhcp.vm.provision "shell", inline: <<-SHELL
echo "Configuring DHCP server"
SHELL
end
# WEB
config.vm.define "WEB" do |web|
web.vm.box = "rockyinfo"
web.vm.hostname = "web"
web.vm.network "public_network", type: "dhcp"
web.vm.provision "shell", inline: <<-SHELL
echo "Configuring WEB server"
SHELL
end
# DB
config.vm.define "DB" do |db|
db.vm.box = "rockyinfo"
db.vm.hostname = "db"
db.vm.network "public_network", type: "dhcp"
db.vm.provision "shell", inline: <<-SHELL
echo "Configuring BBDD server"
SHELL
end
end