-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
101 lines (88 loc) · 3 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
VAGRANT_BOX_UBUNTU_20 = "bento/ubuntu-20.04"
VAGRANT_BOX_UBUNTU_22 = "bento/ubuntu-22.04"
VAGRANT_BOX_CENTOS = "bento/centos-7.9"
VAGRANT_BOX_ROCKY = "bento/rockylinux-9"
VAGRANT_BOX_AMAZON = "bento/amazonlinux-2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.boot_timeout = 300
# Define VMs with static private IP addresses, vcpu, memory and vagrant-box.
boxes = [
{
:name => "test-ubuntu",
:box => VAGRANT_BOX_UBUNTU_20,
:ram => 512,
:vcpu => 1,
:ip => "192.168.56.10",
:port_forward => [
{
:guest_port => 22,
:host_port => 2222,
:host_ip => "",
:app_id => "ssh"
}
]
},
]
# Provision each of the VMs.
boxes.each do |instance|
config.vm.define instance[:name] do |machine|
# Setup instance machine
machine.vm.box = instance[:box]
machine.vm.hostname = instance[:name]
# Private Network
machine.vm.network :private_network,
ip: instance[:ip]
# Forward Network
if !instance[:port_forward].empty?
instance[:port_forward].each do |item|
if item[:host_ip] != ""
machine.vm.network "forwarded_port",
guest: item[:guest_port],
host: item[:host_port],
host_ip: item[:host_ip],
id: item[:app_id],
auto_correct: true
else
machine.vm.network "forwarded_port",
guest: item[:guest_port],
host: item[:host_port],
id: item[:app_id],
auto_correct: true
end
end
end
# SSH
machine.ssh.insert_key = false
machine.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'" # avoids 'stdin: is not a tty' error.
machine.ssh.private_key_path = ["#{ENV['HOME']}/.ssh/id_rsa","#{ENV['HOME']}/.vagrant.d/insecure_private_key"]
# Provision
machine.vm.provision "shell",
inline: <<-SCRIPT
printf "%s\n" "#{File.read("#{ENV['HOME']}/.ssh/id_rsa.pub")}" > /home/vagrant/.ssh/authorized_keys
chown -R vagrant:vagrant /home/vagrant/.ssh
apt-get update
apt-get install curl wget git unzip -y
git --version
cd /tmp
EXA_VERSION=$(curl -s "https://api.github.com/repos/ogham/exa/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
curl -Lo exa.zip "https://github.com/ogham/exa/releases/latest/download/exa-linux-x86_64-v${EXA_VERSION}.zip"
sudo unzip -q exa.zip bin/exa -d /usr/local
exa --version
rm -rf exa.zip
cd /home/vagrant
curl -o- https://raw.githubusercontent.com/asapdotid/asapshell/main/install.sh | bash
SCRIPT
# Folder sync
machine.vm.synced_folder ".", "/home/vagrant/test"
# Virtualbox
machine.vm.provider :virtualbox do |vb|
vb.name = instance[:name]
vb.memory = instance[:ram]
vb.cpus = instance[:vcpu]
end
end
end
end