forked from bertvv/lampstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
91 lines (75 loc) · 2.44 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
# -*- mode: ruby -*-
# vi: ft=ruby :
require 'rbconfig'
require 'yaml'
# Set your default base box here
DEFAULT_BASE_BOX = 'bertvv/centos72'
VAGRANTFILE_API_VERSION = '2'
PROJECT_NAME = '/' + File.basename(Dir.getwd)
hosts = YAML.load_file('vagrant-hosts.yml')
# {{{ Helper functions
def windows?
RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
end
def provision_ansible(config)
if windows?
# Provisioning configuration for shell script.
config.vm.provision 'shell' do |sh|
sh.path = 'scripts/playbook-win.sh'
end
else
# Provisioning configuration for Ansible (for Mac/Linux hosts).
config.vm.provision 'ansible' do |ansible|
ansible.playbook = 'ansible/site.yml'
ansible.sudo = true
end
end
end
# Set options for the network interface configuration. All values are
# optional, and can include:
# - ip (default = DHCP)
# - netmask (default value = 255.255.255.0
# - mac
# - auto_config (if false, Vagrant will not configure this network interface
# - intnet (if true, an internal network adapter will be created instead of a
# host-only adapter)
def network_options(host)
options = {}
if host.key?('ip')
options[:ip] = host['ip']
options[:netmask] = host['netmask'] ||= '255.255.255.0'
else
options[:type] = 'dhcp'
end
options[:mac] = host['mac'].gsub(/[-:]/, '') if host.key?('mac')
options[:auto_config] = host['auto_config'] if host.key?('auto_config')
options[:virtualbox__intnet] = true if host.key?('intnet') && host['intnet']
options
end
def custom_synced_folders(vm, host)
return unless host.key?('synced_folders')
folders = host['synced_folders']
folders.each do |folder|
vm.synced_folder folder['src'], folder['dest'], folder['options']
end
end
# }}}
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.ssh.insert_key = false
hosts.each do |host|
config.vm.define host['name'] do |node|
node.vm.box = host['box'] ||= DEFAULT_BASE_BOX
node.vm.box_url = host['box_url'] if host.key? 'box_url'
node.vm.hostname = host['name']
node.vm.network :private_network, network_options(host)
custom_synced_folders(node.vm, host)
node.vm.provider :virtualbox do |vb|
# Remove this to keep default VM name
vb.name = host['name']
# If assigning VMs to a group fails, remove the following line
#vb.customize ['modifyvm', :id, '--groups', PROJECT_NAME]
end
end
end
provision_ansible(config)
end