/
Vagrantfile
145 lines (120 loc) · 3.46 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
137
138
139
140
141
142
143
144
145
require 'ostruct'
require 'yaml'
number_of_nodes = 2
hostname = "vague"
rackspace_flavour = "512MB"
ubuntu_version = "Precise"
y = YAML.load File.open ".chef/rackspace_secrets.yaml"
def titlecase s
"%s%s" % [
s[0].upcase,
s[1..-1].downcase
]
end
rackspace = OpenStruct.new
rackspace.username = y["username"]
rackspace.api_key = y["api_key"]
rackspace.flavor = /#{rackspace_flavour}/
rackspace.image = /#{titlecase(ubuntu_version)}/
rackspace.public_key_path = "./.chef/id_rsa.pub"
rackspace.endpoint = "https://lon.servers.api.rackspacecloud.com/v2"
rackspace.auth_url = "lon.identity.api.rackspacecloud.com"
default_provider = "virtualbox"
full_hostname = hostname
def load_provider_files
h = {}
Dir.glob(".vagrant/machines/*/provider").each do |b|
bits = b.split "/"
h[bits[2]] = File.read(b).strip
end
h
end
def save_provider_files h
h.each_pair do |name, provider|
# puts "Recording provider for %s" % [
# name
# ]
File.open "%s/%s/%s/%s" % [
".vagrant",
"machines",
name,
"provider"
], "w" do |f|
f.write provider
end
end
end
passed_provider = nil
ARGV.each_index do |i|
if ARGV[i] == "--provider"
passed_provider = ARGV[i + 1]
end
end
if passed_provider
default_provider = passed_provider
node_providers = {}
else
node_providers = load_provider_files
end
Vagrant.configure("2") do |config|
config.butcher.knife_config_file = '.chef/knife.rb'
number_of_nodes.times do |n|
index = "%02d" % [
n + 1
]
config.vm.define :"#{hostname}_#{index}" do |config|
node_providers["#{hostname}_#{index}"] ||= default_provider
provider = node_providers["#{hostname}_#{index}"]
case provider
when "rackspace"
box = "dummy"
else
box = "%s64" % [
ubuntu_version.downcase
]
full_hostname = "%s-%s" % [
hostname,
ENV["USER"]
]
end
config.vm.box = box
config.vm.box_url = "http://files.vagrantup.com/%s.box" % [
box
]
config.vm.hostname = "%s-%s" % [
hostname,
index
]
config.vm.provider :rackspace do |rs|
rs.username = rackspace.username
rs.api_key = rackspace.api_key
rs.flavor = rackspace.flavor
rs.image = rackspace.image
rs.public_key_path = rackspace.public_key_path
rs.endpoint = rackspace.endpoint
rs.auth_url = rackspace.auth_url
end
if provider == "rackspace"
config.ssh.private_key_path = "./.chef/id_rsa"
config.ssh.username = "root"
config.vm.provision :shell, :inline => "curl -L https://www.opscode.com/chef/install.sh | bash"
end
config.vm.provision :chef_client do |chef|
chef.node_name = "%s-%s" % [
full_hostname,
index
]
chef.environment = "vagrant"
chef.chef_server_url = "https://chef.theodi.org"
chef.validation_client_name = "chef-validator"
chef.validation_key_path = ".chef/chef-validator.pem"
chef.run_list = chef.run_list = [
"recipe[git]"
]
end
end
end
end
at_exit do
save_provider_files node_providers
end