-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
70 lines (56 loc) · 3.04 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- mode: ruby -*-
# vi: set ft=ruby :
# A Vagrantfile to set up three VMs, two webservers and a database server,
# connected together using an internal network with manually-assigned
# IP addresses for the VMs.
# @author: Irsyaad Rijwan
Vagrant.configure("2") do |config|
# Using ubuntu/64 box
config.vm.box = "ubuntu/focal64"
# Insert the key manually
# To avoid getting stuck in ssh session (Windows Error)
config.ssh.insert_key = false
config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
# Here is the section for defining the database server, which I have
# named "dbserver".
config.vm.define "dbserver" do |dbserver|
dbserver.vm.hostname = "dbserver"
# VM's private network IP 192.168.56.12
dbserver.vm.network "private_network", ip: "192.168.56.12"
dbserver.vm.synced_folder ".", "/vagrant", owner: "vagrant", group: "vagrant", mount_options: ["dmode=775,fmode=777"]
dbserver.vm.provision "shell", path: "build-dbserver-vm.sh"
end
# First VM "webserver1"
config.vm.define "webserver1" do |webserver1|
# These are options specific to the webserver VM
webserver1.vm.hostname = "webserver1"
# Port forwarding to IP address 127.0.0.1 port 8081
webserver1.vm.network "forwarded_port", guest: 80, host: 8081, host_ip: "127.0.0.1"
# VM's private network IP 192.168.56.13
webserver1.vm.network "private_network", ip: "192.168.56.13"
# Change the folders and files permissions to allow vagrant to access or exectute folders or files on the host machine
webserver1.vm.synced_folder ".", "/vagrant", owner: "vagrant", group: "vagrant", mount_options: ["dmode=775,fmode=777"]
# Shell commands to provision the webserver1.
webserver1.vm.provision "shell", path: "build-webserver1-vm.sh"
# Shell commands to start the webserver1.
# On the background using tmux
webserver1.vm.provision "shell", path: "start-web-app1.sh"
end
# Second VM "webserver2"
config.vm.define "webserver2" do |webserver2|
# These are options specific to the webserver VM
webserver2.vm.hostname = "webserver1"
# Port forwarding to IP address 127.0.0.1 port 8082
webserver2.vm.network "forwarded_port", guest: 80, host: 8082, host_ip: "127.0.0.1"
# VM's private network IP 192.168.56.14
webserver2.vm.network "private_network", ip: "192.168.56.14"
# Change the folders and files permissions to allow vagrant to access or exectute folders or files on the host machine
webserver2.vm.synced_folder ".", "/vagrant", owner: "vagrant", group: "vagrant", mount_options: ["dmode=775,fmode=777"]
# Shell commands to provision the webserver1.
webserver2.vm.provision "shell", path: "build-webserver2-vm.sh"
# Shell commands to start the webserver2.
# On the background using tmux
webserver2.vm.provision "shell", path: "start-web-app2.sh"
end
end
# LocalWords: webserver xenial64