-
Notifications
You must be signed in to change notification settings - Fork 376
/
Copy pathVagrantfile
136 lines (114 loc) · 4.7 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
126
127
128
129
130
131
132
133
134
135
136
# -*- mode: ruby -*-
# vi: set ft=ruby :
nodes_config = (JSON.parse(File.read("nodes.json")))['nodes']
VAGRANTFILE_API_VERSION = "2"
ENV["LC_ALL"] = "en_US.UTF-8"
proxy = ENV['http_proxy'] || ""
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if ARGV[1] and \
(ARGV[1].split('=')[0] == "--provider" or ARGV[2])
provider = (ARGV[1].split('=')[1] || ARGV[2])
else
provider = (ENV['VAGRANT_DEFAULT_PROVIDER'] || :virtualbox).to_sym
end
puts "Detected #{provider}"
if ENV['http_proxy']
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = proxy
config.proxy.https = proxy
config.apt_proxy.http = proxy
config.apt_proxy.https= proxy
config.proxy.no_proxy = "localhost,127.0.0.1,.hpecorp.net,github.hpe.com,ci-node,monitoring-node,app-server-node-1,app-server-node-2,app-server-node-3,app-server-node-4,ci-repo,mongodb-node"
end
end
nodes_config.each do |node|
node_name = node["node"] # name of node
config.ssh.insert_key = false
config.ssh.private_key_path = '~/.vagrant.d/insecure_private_key'
# For each node
config.vm.define node_name do |config|
ports = node['ports']
ports.each do |port|
config.vm.network :forwarded_port,
host: port['host'],
guest: port['guest'],
auto_correct: port['auto_correct']
end
config.vm.hostname = node['hostname']
config.vm.network :private_network, ip: node['ip']
# config.vm.box = 'bento/ubuntu-16.04'
if provider==:virtualbox
puts "provider= #{provider}"
config.vm.box = 'bento/ubuntu-16.04'
config.vm.synced_folder "provision", "/provision"
config.vm.provider :virtualbox do |vb, override|
vb.customize ["modifyvm", :id, "--memory", node['memory']]
vb.customize ["modifyvm", :id, "--name", node['node']]
vb.customize ["modifyvm", :id, "--cpus", node['cpus']]
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.customize ["modifyvm", :id, "--usb", "off"]
end
end
if provider==:libvirt
puts "provider= #{provider}"
config.vm.box = 'peru/ubuntu-16.04-server-amd64'
config.vm.synced_folder "provision", "/provision" , type: "rsync"
config.vm.provider :libvirt do |vb, override|
vb.memory = node['memory']
vb.cpus = node['cpus'] || 2
vb.driver = "kvm"
vb.host = "localhost"
vb.uri = "qemu:///system"
end
end
if provider=="azure"
config.vm.synced_folder "provision", "/provision"
config.vm.provider :azure do |azure, override|
config.vm.box = 'azure'
azure.vm_image_urn = 'canonical:ubuntuserver:16.04-DAILY-LTS:latest'
azure.tenant_id = ENV['AZURE_TENANT_ID']
azure.client_id = ENV['AZURE_CLIENT_ID']
azure.client_secret = ENV['AZURE_CLIENT_SECRET']
azure.subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
azure.resource_group_name = 'DojoLabs'
azure.vm_size = node['vm_size']
azure.vm_name = node['node']
azure.location = 'centralus'
azure.dns_name = node['hostname'] + "-" + ENV['LAB_SUFFIX']
azure.private_ip_allocation_method = 'Static'
azure.private_ip_address = node['ip']
azure.virtual_network_name = 'DojoLabsVNet'
end
end
if Vagrant.has_plugin?("vagrant-hostsupdater")
config.hostsupdater.aliases = node['aliases']
end
if Vagrant.has_plugin?("vagrant-cachier") && node['apt_cache']
config.cache.scope = :machine
config.cache.enable :apt
config.cache.enable :gem
config.cache.enable :bower
config.cache.enable :npm
end
config.vm.provision "fix-no-tty", type: "shell" do |s|
s.privileged = false
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
end
if provider==:libvirt
# config.vm.provision :"shell", :inline => "sudo mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant"
# config.vm.provision :"shell", :inline => "sudo mount -t vboxsf -o uid=1000,gid=1000 provision /provision"
end
config.vm.provision "shell" do |s|
ansible_limit = "--limit=" + node['hostname']
s.env = {http_proxy:ENV['http_proxy'], https_proxy:ENV['http_proxy']}
s.path = "scripts/provision.sh"
s.privileged = false
s.args = ["--inventory-file=hosts",
ansible_limit,
"--extra-vars='ansible_ssh_user=vagrant'",
"--user=vagrant",
node['playbook']]
end
end
end
end