forked from devops-dojo/the-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
107 lines (92 loc) · 3.94 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
nodes_config = (JSON.parse(File.read("nodes.json")))['nodes']
VAGRANTFILE_API_VERSION = "2"
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 Vagrant.has_plugin?("vagrant-proxyconf")
# config.proxy.http = ENV['http_proxy'] || ""
# config.proxy.https = ENV['http_proxy'] || ""
# config.apt_proxy.http = ENV['http_proxy'] || ""
# config.apt_proxy.https= nil
# config.proxy.no_proxy = "localhost,127.0.0.1,.hpecorp.net,github.hpe.com,ci-repo,monitoring-node,app-server-node-1,app-server-node-2,app-server-node-3,app-server-node-4,ci-repo,mongodb-node"
# 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.synced_folder "provision", "/provision"
if provider=="virtualbox"
config.vm.box = 'bento/ubuntu-16.04'
config.vm.provider :virtualbox do |vb|
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=="azure"
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
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"
config.vm.provision "shell" do |s|
ansible_limit = "--limit=" + node['hostname']
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