-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
125 lines (102 loc) · 4.2 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
current_dir = File.dirname(File.expand_path(__FILE__))
hosts = YAML.load_file("#{current_dir}/inventory/hosts.yml")
scenario = hosts['all']['vars']['scenario']
hosts = hosts['all']['children'][scenario]
if (hosts.has_key? "children")
children = Array[]
hosts['children'].each do | key, value |
children.push(value['hosts'].keys[0])
end
hosts = children
else
hosts = hosts['hosts'].keys
end
ENV["VAGRANT_EXPERIMENTAL"]="1"
Vagrant.configure("2") do |config|
hosts.each do |host|
host_config = YAML.load_file("#{current_dir}/inventory/host_vars/#{host}/vagrant.yml")
config.vm.define host do |machine|
machine.vm.boot_timeout = host_config['boot_timeout']
machine.vm.box = host_config['box']
machine.vm.hostname = host
if (host_config.has_key? "network")
machine.vm.network host_config['network']['net'], bridge: host_config['network']['bridge']
end
if (host_config.has_key? "intnet")
machine.vm.network "private_network", ip: host_config['intnet']['ip']
end
### hyper-v config
if (host_config['provider'] == 'hyper-v')
if (host_config.has_key? "synced_folder")
machine.vm.synced_folder host_config['synced_folder'], "/home/vagrant/Documents", type: "smb"
end
$preStartScript = <<-SCRIPT
Set-VM #{host} -EnhancedSessionTransportType HVSocket -verbose
Set-VMProcessor -VMName #{host} -HwThreadCountPerCore 2
Set-VMFirmware -VMName #{host} -FirstBootDevice (Get-VMHardDiskDrive -VMName #{host})
SCRIPT
machine.vm.provider "hyperv" do |h,override|
#h.enable_enhanced_session_mode = true
h.enable_virtualization_extensions = true
h.vmname = host
h.cpus = host_config['cpus']
h.memory = host_config['memory']
override.trigger.before :'VagrantPlugins::HyperV::Action::StartInstance', type: :action do |trigger|
trigger.info = "---------------- Running pre Start Triggers -----------------"
trigger.run = {inline: $preStartScript}
end
end
if host_config['gui']
machine.vm.provision "shell", path: "./files/install_xrdp.sh"
end
end
### hyper-v config
### virtualbox config
if (host_config['provider'] == 'virtualbox')
if (host_config.has_key? "synced_folder")
machine.vm.synced_folder host_config['synced_folder'], "/home/vagrant/Documents"
end
machine.vm.provider :virtualbox do |vb|
vb.name = host
vb.gui = host_config['gui']
vb.customize ["modifyvm", :id, "--memory", host_config['memory']]
if (host_config.has_key? "customize_opts")
host_config['customize_opts'].each do |opt, setting|
vb.customize ["modifyvm", :id, opt, setting]
end
end
end
end
### virtualbox config
if (host_config.has_key? "forwarded_port")
host_config['forwarded_port'].each do |host, guest|
machine.vm.network "forwarded_port", guest: guest, host: host
end
end
machine.ssh.username = host_config['ansible_user']
machine.ssh.insert_key = "false"
if (host_config.has_key? "file_provision")
host_config['file_provision'].each do |src, dest|
machine.vm.provision "file", source: src, destination: dest
end
end
if (host_config.has_key? "shell_provision")
host_config['shell_provision'].each do | cmd |
machine.vm.provision "shell", privileged: false, inline: cmd
end
end
machine.vm.provision "shell", path: "./preinstall.sh"
machine.vm.provision "ansible_local" do |ansible|
ansible.inventory_path = "inventory/hosts.yml"
ansible.limit = "all"
ansible.playbook = "converge.yml"
ansible.galaxy_role_file = "roles/requirements.yml"
ansible.limit = host
ansible.inventory_path = "inventory/hosts.yml"
end
end
end
end