forked from bertvv/ansible-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
107 lines (86 loc) · 2.51 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
104
105
106
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'rbconfig'
require 'yaml'
# Set the base box here
BASE_BOX = 'centos71-nocm'
BASE_BOX_URL = 'https://tinfbo2.hogent.be/pub/vm/centos71-nocm-1.0.16.box'
#
# No changes needed below this point
#
VAGRANTFILE_API_VERSION = '2'
PROJECT_NAME = '/' + File.basename(Dir.getwd)
hosts = YAML.load_file('vagrant_hosts.yml')
# {{{ Helper functions
def is_windows
RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
end
def provision_ansible(config)
if is_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.has_key?('ip')
options[:ip] = host['ip']
options[:netmask] = host['netmask'] ||= '255.255.255.0'
else
options[:type] = 'dhcp'
end
if host.has_key?('mac')
options[:mac] = host['mac'].gsub(/[-:]/, '')
end
if host.has_key?('auto_config')
options[:auto_config] = host['auto_config']
end
if host.has_key?('intnet') && host['intnet']
options[:virtualbox__intnet] = true
end
options
end
def custom_synced_folders(vm, host)
if host.has_key?('synced_folders')
folders = host['synced_folders']
folders.each do |folder|
vm.synced_folder folder['src'], folder['dest'], folder['options']
end
end
end
# }}}
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = BASE_BOX
config.vm.box_url = BASE_BOX_URL
config.ssh.insert_key = false # Keep using the insecure key
hosts.each do |host|
config.vm.provider 'virtualbox' do |vb|
vb.customize ['modifyvm', :id, '--groups', PROJECT_NAME]
end
config.vm.define host['name'] do |node|
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|
vb.name = host['name']
end
end
end
provision_ansible(config)
end