-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vagrantfile
59 lines (51 loc) · 1.62 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
# By: mrlucasfreitas
# https://github.com/mrlucasfreitas
# Install vagrant-hostsupdater plugin
unless Vagrant.has_plugin? 'vagrant-hostsupdater'
system('vagrant plugin install vagrant-hostsupdater')
end
# Install public key in VM
# The public key must be located in ~/.ssh/id_rsa
ssh_pub_key = File.read("#{Dir.home}/.ssh/id_rsa.pub")
ssh_setup_script = <<-SCRIPT
ssh_authorized_keys="/home/vagrant/.ssh/authorized_keys"
echo '#{ssh_pub_key}' >> "$ssh_authorized_keys"
SCRIPT
# Ansible variables
ANSIBLE_CONFIG = File.join(File.dirname(__FILE__), "ansible.cfg")
ansible_provision_playbook = ENV["ANSIBLE_PROVISION_PLAYBOOK"] || "test.yml"
# Define VM images and hostnames
hosts = [
{
:name => "centos7",
:box => "bento/centos-7",
:box_v => "202002.04.0",
:vm_name => "vagrant-centos7",
:hostname => "vagrant-centos7.local",
:ip => "172.16.10.53"
}
]
# Define VM configuration
Vagrant.configure("2") do |config|
hosts.each do |host|
config.vm.define host[:name] do |m|
m.vm.box = host[:box]
m.vm.box_version = host[:box_v]
m.vm.hostname = host[:hostname]
m.vm.network :private_network, ip: host[:ip]
if host[:name] =~ /^freebsd/ then
m.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
m.ssh.shell = "sh"
m.vm.base_mac = host[:base_mac]
m.vm.boot_timeout = 600
end
m.vm.provider :virtualbox do |vb|
vb.name = host[:vm_name]
vb.gui = false
vb.cpus = 1
vb.memory = 512
end
m.vm.provision "shell", inline: ssh_setup_script, privileged: false
end
end
end