-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathVagrantfile
175 lines (152 loc) · 6.16 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Vagrant.require_version ">= 1.9.1"
require 'json'
VAGRANTFILE_API_VERSION = "2"
# Profile search path:
$profile_path = ["current.profile",
"profiles/3node-nonsecure.profile"]
###############################################################################
# Loads a profile, which is a JSON file describing a specific configuation.
#
# The user should create a symlink from current.profile to the desired
# profile.
def loadProfile()
$profile_path.each { |file|
if file and File.file?(file)
puts "Loading profile %s\n" % [File.realpath(file)]
return JSON.parse( IO.read( file ), opts = { symbolize_names: true } )
end
}
end
# Pull the HDP version out of the hdp.repo file
def findVersion(profile)
if (profile[:os] == "centos6")
path = 'files/repos/centos6.hdp.repo.%s' % profile[:hdp_short_version]
# elsif (profile[:os] == "centos7")
# path = 'files/repos/centos7.hdp.repo.%s' % profile[:hdp_short_version]
# elsif (profile[:os] == "ubuntu14")
# path = 'files/repos/ubuntu14.hdp.list.%s' % profile[:hdp_short_version]
end
fileObj = File.new(path, 'r')
match = /^#VERSION_NUMBER=(?<ver>[-0-9.]*)/.match(fileObj.gets)
fileObj.close()
version = match['ver']
versions = version.split(".")
major = versions[0].to_i
minor = versions[1].to_i
patch = versions[2].to_i
puts "HDP Build = %s\n" % version
return [version, major, minor, patch]
end
###############################################################################
# Define cluster
profile = loadProfile()
# Set defaults.
default_os = "centos6"
default_hdp_short_version = "2.6.1"
default_ambari_version = "2.4.2"
default_java_version = "java-1.7.0-openjdk"
profile[:hdp_short_version] ||= default_hdp_short_version
profile[:ambari_version] ||= default_ambari_version
profile[:java_version] ||= default_java_version
profile[:os] ||= default_os
profile[:vm_cpus] ||= 2
profile[:am_mem] ||= 512
profile[:server_mem] ||= 768
profile[:client_mem] ||= 1024
profile[:remote] ||= false
(hdp_version, hdp_version_major, hdp_version_minor, hdp_version_patch) = findVersion(profile)
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if Vagrant.has_plugin?("vagrant-cachier")
# Configure cached packages to be shared between instances of the same base box.
config.cache.scope = :box
end
config.ssh.insert_key = false
# All Vagrant configuration is done here. The most common configuration
# Every Vagrant virtual environment requires a box to build off of.
if (profile[:os] == "centos6")
# config.vm.box = "puppetlabs/centos-6.6-64-puppet"
if profile[:remote]
config.vm.box = "tknerr/managed-server-dummy"
else
config.vm.box = "omalley/structor-centos6.7"
end
package_version = "_" + (hdp_version.gsub /[.-]/, '_')
platform_start_script_path = "rc.d/init.d"
# elsif (profile[:os] == "centos7")
# config.vm.box = "puppetlabs/centos-7.0-64-puppet"
# package_version = "_" + (hdp_version.gsub /[.-]/, '_')
# platform_start_script_path = "rc.d/init.d"
# elsif (profile[:os] == "ubuntu")
# config.vm.box = "ubuntu/trusty64"
# package_version = "-" + (hdp_version.gsub /[.-]/, '-')
# platform_start_script_path = "init.d"
end
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", profile[:vm_mem] ]
vb.customize ["modifyvm", :id, "--cpus", profile[:vm_cpus] ]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
profile[:nodes].each do |node|
config.vm.define node[:hostname] do |node_config|
if profile[:remote]
node_config.vm.provider :managed do |managed, override|
managed.server = node[:hostname] + "." + profile[:domain]
override.ssh.username = "root"
override.ssh.private_key_path = "id_rsa.pem"
end
else
node_config.vm.network :private_network, ip: node[:ip]
end
node_config.vm.hostname = node[:hostname] + "." + profile[:domain]
node_config.ssh.forward_agent = true
node_config.vm.provision "puppet" do |puppet|
puppet.module_path = "modules"
puppet.environment_path = "environments"
puppet.environment = "structor"
puppet.options = ["--libdir", "/vagrant",
"--verbose", "--debug",
"--fileserverconfig=/vagrant/fileserver.conf"]
puppet.facter = {
"hdp_short_version" => profile[:hdp_short_version],
"ambari_version" => profile[:ambari_version],
"package_version" => package_version,
"java_version" => profile[:java_version],
"platform_start_script_path" => platform_start_script_path,
"am_mem" => profile[:am_mem],
"client_mem" => profile[:client_mem],
"server_mem" => profile[:server_mem],
"vm_mem" => profile[:vm_mem],
"vm_cpus" => profile[:vm_cpus],
"domain" => profile[:domain],
"security" => profile[:security],
"realm" => profile[:realm],
"clients" => profile[:clients],
"extras" => profile[:extras],
"hostname" => node[:hostname],
"nodes" => profile[:nodes],
"profile" => profile,
"roles" => node[:roles],
"hdp_version" => hdp_version,
"hdp_version_major" => hdp_version_major,
"hdp_version_minor" => hdp_version_minor,
"hdp_version_patch" => hdp_version_patch,
"hive_options" => profile[:hive_options],
}
end
end
end
end