-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
81 lines (68 loc) · 2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Vagrant.require_version ">= 1.9.0"
require 'yaml'
dir = File.dirname(File.expand_path(__FILE__))
if !File.file?("#{dir}/provision/config/vm_config.yml")
print "Please rename and configure #{dir}/provision/config/sample/vm_config_sample.yml to
#{dir}/provision/config/vm_config.yml to continue\n"
exit
end
if !File.file?("#{dir}/provision/config/synced_folder.yml")
print "Please rename and configure #{dir}/provision/config/sample/synced_folder_sample.yml to
#{dir}/provision/config/synced_folder.yml to continue\n"
exit
end
if !File.file?("#{dir}/provision/config/host_aliases.yml")
print "Please rename and configure #{dir}/provision/config/sample/host_aliases_sample.yml to
#{dir}/provision/config/host_aliases.yml to continue\n"
exit
end
vm_config = YAML.load_file("#{dir}/provision/config/vm_config.yml")
synced_folder = YAML.load_file("#{dir}/provision/config/synced_folder.yml")
host_aliases = YAML.load_file("#{dir}/provision/config/host_aliases.yml")
Vagrant.configure(2) do |config|
config.vm.box = "#{vm_config['box']['name']}"
if !vm_config["box"]["url"].nil?
config.vm.box_url = "#{vm_config['box']['url']}"
end
config.vm.define "#{vm_config['vm']['name']}"
config.vm.network :private_network, ip: "#{vm_config['vm']['network']['private_network']}"
config.vm.hostname = "#{vm_config['vm']['hostname']}"
config.ssh.insert_key = false
config.ssh.forward_agent = true
config.vm.provider :virtualbox do |v|
v.name = "#{vm_config['vm']['name']}"
v.memory = "#{vm_config['vm']['memory']}"
v.cpus = "#{vm_config['vm']['cpus']}"
v.customize [
"modifyvm", :id,
"--natdnshostresolver1", "on",
"--cableconnected1", "on",
]
end
config.vm.provision :ansible_local do |ansible|
ansible.install_mode = "pip"
ansible.version = "2.2.1.0"
ansible.galaxy_role_file = "provision/requirements.yml"
ansible.playbook = "provision/playbook.yml"
ansible.sudo = true
ansible.verbose = false
ansible.limit = 'all'
end
synced_folder.each do |i, folder|
if folder['source'] != '' && folder['target'] != ''
config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}", type: "#{folder['type']}"
end
end
if Vagrant.has_plugin?('vagrant-hostmanager')
hosts = Array.new()
host_aliases.each do |host_alias|
hosts.push(host_alias)
end
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = false
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
config.hostmanager.aliases = hosts
end
end