forked from sloria/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVagrantfile
103 lines (87 loc) · 3.74 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
102
103
# Inspired and adapted from https://github.com/geerlingguy/ansible-role-test-vms... thanks a lot!
# -*- mode: ruby -*-
# vi: set ft=ruby :
require "json"
VAGRANTFILE_API_VERSION = "2"
# Set to 'true' when testing new base box builds locally.
TEST_MODE = false
LOCAL_BOX_DIRECTORY = "file://~/Downloads/"
# Uncomment when explicitly testing VirtualBox.
PROVIDER_UNDER_TEST = "virtualbox"
NETWORK_PRIVATE_IP_PREFIX = "172.16.3."
# Uncomment when explicitly testing VMWare.
# PROVIDER_UNDER_TEST = "vmware"
# NETWORK_PRIVATE_IP_PREFIX = "192.168.3."
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# https://www.vagrantup.com/docs/vagrantfile/ssh_settings.html
config.ssh.insert_key = false
config.ssh.forward_agent = true
config.ssh.private_key_path = ["~/.ssh/id_rsa", "~/.vagrant.d/insecure_private_key"]
# VirtualBox.
# https://www.vagrantup.com/docs/virtualbox/configuration.html
config.vm.provider :virtualbox do |v|
# https://www.vagrantup.com/docs/virtualbox/configuration.html#gui-vs-headless
if ENV['MULTI_DEV_MACHINE_GUI']
v.gui = true
end
# https://www.vagrantup.com/docs/virtualbox/configuration.html#linked-clones
v.linked_clone = true
# https://www.vagrantup.com/docs/virtualbox/configuration.html#vboxmanage-customizations
v.memory = 1024
v.cpus = 3
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--ioapic", "on"]
end
# VMware Fusion.
# https://www.vagrantup.com/docs/vmware/configuration.html
config.vm.provider :vmware_fusion do |v, override|
v.vmx["memsize"] = 1024
v.vmx["numvcpus"] = 3
end
# https://www.vagrantup.com/docs/synced-folders/basic_usage.html
# Replace the default shared folder /vagrant
config.vm.synced_folder ".", "/home/vagrant/dotfiles"
# Configure all extra ~/dotfiles_* directories as shared folders
Dir[File.expand_path('~/dotfiles_*')].each do |dotfile_dir|
config.vm.synced_folder dotfile_dir, "/home/vagrant/" + File.basename(dotfile_dir)
end
# Prepare a dynamic list of Vagrant VMs from a JSON file
vm_ip = 1
json_string = open("Vagrantfile.jsonc").read
parsed_json = JSON.parse(json_string)
parsed_json["vms"].each do |json_vm|
vm_name = json_vm["name"]
vm_box = json_vm["box"]
vm_box_version = json_vm["box_version"]
vm_ip += 1
config.vm.define vm_name do |machine|
machine.vm.hostname = vm_name + "-virtual-machine"
if not TEST_MODE
machine.vm.box = vm_box
else
machine.vm.box = LOCAL_BOX_DIRECTORY + PROVIDER_UNDER_TEST + "-" + vm_name + ".box"
end
if vm_box_version
machine.vm.box_version = vm_box_version
end
machine.vm.network :private_network, ip: NETWORK_PRIVATE_IP_PREFIX + vm_ip.to_s
# Ansible Local: https://www.vagrantup.com/docs/provisioning/ansible_local.html
machine.vm.provision "ansible_local" do |ansible|
# Common options: https://www.vagrantup.com/docs/provisioning/ansible_common.html
ansible.compatibility_mode = "2.0"
ansible.provisioning_path = "/home/vagrant/dotfiles"
ansible.limit = "all"
ansible.inventory_path = "hosts"
ansible.playbook = "playbook_local.yml"
verbose = ENV['MULTI_DEV_MACHINE_VERBOSE']
if verbose
ansible.verbose = verbose
end
tags = ENV['MULTI_DEV_MACHINE_TAGS']
if tags
ansible.tags = tags
end
end
end
end
end