forked from sous-chefs/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
256 lines (224 loc) · 8.63 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# Launch and provision multiple Linux distributions with Vagrant <http://vagrantup.com>
#
# Support:
#
# * precise64: Ubuntu 12.04 (Precise) 64 bit (primary box)
# * lucid32: Ubuntu 10.04 (Lucid) 32 bit
# * lucid64: Ubuntu 10.04 (Lucid) 64 bit
# * centos6: CentOS 6 32 bit
#
# See:
#
# $ vagrant status
#
# The virtual machines are automatically provisioned upon startup with Chef-Solo
# <http://vagrantup.com/v1/docs/provisioners/chef_solo.html>.
#
require 'json'
# Lifted from <https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb>
#
class Hash
def deep_merge!(other_hash)
self.merge(other_hash) do |key, oldval, newval|
oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
newval = newval.to_hash if newval.respond_to?(:to_hash)
oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.dup.deep_merge!(newval) : newval
end
end unless respond_to?(:deep_merge!)
end
STDERR.puts "[Vagrant ] #{Vagrant::VERSION}"
# Automatically install and mount cookbooks from Berksfile on old Vagrant
#
require 'berkshelf/vagrant' if Vagrant::VERSION < '1.1'
distributions = {
:precise64 => {
:url => 'http://files.vagrantup.com/precise64.box',
:run_list => %w| apt build-essential vim java monit elasticsearch elasticsearch::plugins elasticsearch::proxy elasticsearch::aws elasticsearch::data elasticsearch::monit |,
:ip => '33.33.33.10',
:primary => true,
:node => {
:elasticsearch => {
:path => {
:data => %w| /usr/local/var/data/elasticsearch/disk1 /usr/local/var/data/elasticsearch/disk2 |
},
:data => {
:devices => {
"/dev/sdb" => {
:file_system => "ext3",
:mount_options => "rw,user",
:mount_path => "/usr/local/var/data/elasticsearch/disk1",
:format_command => "mkfs.ext3 -F",
:fs_check_command => "dumpe2fs"
},
"/dev/sdc" => {
:file_system => "ext3",
:mount_options => "rw,user",
:mount_path => "/usr/local/var/data/elasticsearch/disk2",
:format_command => "mkfs.ext3 -F",
:fs_check_command => "dumpe2fs"
}
}
}
}
}
},
:centos6 => {
# Note: Monit cookbook broken on CentOS
:url => 'https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-centos-6.3.box',
:run_list => %w| yum::epel build-essential vim java elasticsearch elasticsearch::proxy elasticsearch::data |,
:ip => '33.33.33.11',
:primary => false,
:node => {
:elasticsearch => {
:path => {
:data => "/usr/local/var/data/elasticsearch/disk1"
},
:data => {
:devices => {
"/dev/sdb" => {
:file_system => "ext3",
:mount_options => "rw,user",
:mount_path => "/usr/local/var/data/elasticsearch/disk1",
:format_command => "mkfs.ext3 -F",
:fs_check_command => "dumpe2fs"
}
}
},
:nginx => {
:user => 'nginx'
}
}
}
}
}
node_config = {
:java => {
:install_flavor => "openjdk",
:jdk_version => "7"
},
:elasticsearch => {
:cluster => { :name => "elasticsearch_vagrant" },
:plugins => {
'karmi/elasticsearch-paramedic' => {
:url => 'https://github.com/karmi/elasticsearch-paramedic/archive/master.zip'
}
},
:limits => {
:nofile => 1024,
:memlock => 512
},
:logging => {
:discovery => 'TRACE',
'index.indexing.slowlog' => 'INFO, index_indexing_slow_log_file'
},
:nginx => {
:user => 'www-data',
:users => [{ username: 'USERNAME', password: 'PASSWORD' }]
},
# For testing flat attributes:
"index.search.slowlog.threshold.query.trace" => "1ms",
# For testing deep attributes:
:discovery => { :zen => { :ping => { :timeout => "9s" } } },
# For testing custom configuration
:custom_config => {
'threadpool.index.type' => 'fixed',
'threadpool.index.size' => '2'
}
}
}
if ENV['CONFIG']
# See e.g. https://gist.github.com/karmi/2050769#file-node-example-json
begin
custom_config = JSON.parse(File.read(ENV['CONFIG']), symbolize_names: true)
rescue Exception => e
STDERR.puts "[!] Error when reading the configuration file:",
e.inspect
end
else
custom_config = {}
end
Vagrant::Config.run do |config|
distributions.each_pair do |name, options|
config.vagrant.dotfile_name = '.vagrant-1' if Vagrant::VERSION < '1.1'
config.vm.define name, :options => options[:primary] do |box_config|
box_config.vm.box = name.to_s
box_config.vm.box_url = options[:url]
box_config.vm.host_name = name.to_s
if Vagrant::VERSION < '1.1'
box_config.vm.network :hostonly, options[:ip]
else
config.vm.network :private_network, ip: options[:ip]
end
box_config.berkshelf.enabled = true if Vagrant::VERSION > '1.1'
# Box customizations
# 1. Limit memory to 512 MB
#
if Vagrant::VERSION < '1.1'
box_config.vm.customize ["modifyvm", :id, "--memory", 512]
else
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 512]
end
end
# 2. Create additional disks
#
if Vagrant::VERSION < '1.1'
if name == :precise64 or name == :centos6
disk1, disk2 = "tmp/disk-#{Time.now.to_f}.vdi", "tmp/disk-#{Time.now.to_f}.vdi"
box_config.vm.customize ["createhd", "--filename", disk1, "--size", 250]
box_config.vm.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 1,"--type", "hdd", "--medium", disk1]
box_config.vm.customize ["createhd", "--filename", disk2, "--size", 250]
box_config.vm.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 2,"--type", "hdd", "--medium", disk2]
end
else
if name == :precise64 or name == :centos6
config.vm.provider :virtualbox do |vb|
disk1, disk2 = "tmp/disk-#{Time.now.to_f}.vdi", "tmp/disk-#{Time.now.to_f}.vdi"
vb.customize ["createhd", "--filename", disk1, "--size", 250]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 1,"--type", "hdd", "--medium", disk1]
vb.customize ["createhd", "--filename", disk2, "--size", 250]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 2,"--type", "hdd", "--medium", disk2]
end
end
end
# Update packages on the machine
#
config.vm.provision :shell do |shell|
shell.inline = %Q{
which apt-get > /dev/null 2>&1 && apt-get update --quiet --yes || true;
which yum > /dev/null 2>&1 && yum update -y || true;
}
end if ENV['UPDATE']
# Install latest Chef on the machine
#
config.vm.provision :shell do |shell|
version = ENV['CHEF'].match(/^\d+/) ? ENV['CHEF'] : nil
if version
shell.inline = %Q{
which apt-get > /dev/null 2>&1 && apt-get install curl --quiet --yes || true;
which yum > /dev/null 2>&1 && yum install curl -y || true;
test -d "/opt/chef" && grep 'chef #{version}' /opt/chef/version-manifest.txt || curl -# -L http://www.opscode.com/chef/install.sh | sudo bash -s -- #{version ? "-v #{version}" : ''};
/opt/chef/embedded/bin/gem list pry | grep pry || /opt/chef/embedded/bin/gem install pry --no-ri --no-rdoc || true;
}
else
shell.inline = %Q{
which apt-get > /dev/null 2>&1 && apt-get install curl --quiet --yes || true;
which yum > /dev/null 2>&1 && yum install curl -y || true;
test -d "/opt/chef" && chef-solo -v | grep 11 || curl -# -L http://www.opscode.com/chef/install.sh | sudo bash -s --;
/opt/chef/embedded/bin/gem list pry | grep pry || /opt/chef/embedded/bin/gem install pry --no-ri --no-rdoc;
}
end
end if ENV['CHEF']
# Provision the machine with Chef Solo
#
box_config.vm.provision :chef_solo do |chef|
chef.data_bags_path = './tmp/data_bags'
chef.provisioning_path = '/etc/vagrant-chef'
chef.log_level = :debug
chef.run_list = options[:run_list]
chef.run_list << 'elasticsearch::test' if ENV['TEST']
chef.json = node_config.dup.deep_merge!(options[:node]).deep_merge!(custom_config)
end
end
end
end