-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVagrantfile
69 lines (53 loc) · 2.35 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
# -*- mode: ruby -*-
# # vi: set ft=ruby :
require 'fileutils'
Vagrant.require_version ">= 1.6.0"
require_relative 'common'
Vagrant.configure("2") do |config|
# always use Vagrants insecure key
config.ssh.insert_key = false
config.vm.box = "test/coreos"
master_ips = Common.get_ips(Common::MASTER_BOX)
[Common::MASTER_BOX, Common::WORKER_BOX].each do |box|
Common.get_ips(box).each_with_index do |ip, index|
instance_name = box[:name] + "-#{index+1}"
config.vm.define instance_name do |node|
node.vm.provider :virtualbox do |v|
# On VirtualBox, we don't have guest additions or a functional vboxsf
# in CoreOS, so tell Vagrant that so it can be smarter.
v.check_guest_additions = false
v.functional_vboxsf = false
end
# plugin conflict
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end
# Inject the cloud config
if File.exist?(Common::CLOUD_CONFIG_PATH)
node.vm.provision :file, :source => "#{Common::CLOUD_CONFIG_PATH}", :destination => "/tmp/vagrantfile-user-data"
node.vm.provision :shell, :inline => "cp /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
end
node.vm.hostname = instance_name
node.vm.provider :virtualbox do |vb|
vb.gui = false
vb.memory = box[:memory]
vb.cpus = box[:cpus]
end
node.vm.network :private_network, ip: ip
# Get our environment variables
environment_variables = {
:ncp_unique_cloud_id => (index+1).to_s,
:ncp_ip => ip.to_s,
:ncp_masters => "\\\"" + master_ips.join(' ') + "\\\"",
:ncp_num_masters => master_ips.length.to_s
}.map { |key, value| "#{key.upcase}=#{value}" }.join("\n")
# Inject our environment variables.
node.vm.provision :shell, inline: "echo \"#{environment_variables}\" | tee -a /etc/ncp_environment", :privileged => true
# We need to restart our system to make cloud config take effect before we try and run a script it creates.
node.vm.provision :reload
# Start (TODO: Make this start on boot instead of via vagrant)
node.vm.provision :shell, :inline => "/home/core/#{box[:script]}", :privileged => true
end
end
end
end