-
Notifications
You must be signed in to change notification settings - Fork 23
/
Vagrantfile
156 lines (131 loc) · 5.15 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Copyright (c) 2016 Mirantis Inc.
#
# Licensed 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.
VAGRANTFILE_API_VERSION = "2"
CURRENT_DIR = File.expand_path(File.dirname(__FILE__))
CLOUD_CONFIG_USERNAME = "ansible"
CLOUD_CONFIG_URL = "10.0.0.10:9999"
CLOUD_CONFIG_KEY = File.join(
CURRENT_DIR,
"containerization", "files", "devconfigs", "ansible_ssh_keyfile.pub")
CLOUD_CONFIG_GEN = File.join(CURRENT_DIR, "devenv", "vagrant-cloud-config.py")
CLOUD_CONFIG_TOKEN = "26758c32-3421-4f3d-9603-e4b5337e7ecc"
cloud_config_file = ""
cloud_config_file = `#{CLOUD_CONFIG_GEN} #{CLOUD_CONFIG_USERNAME} #{CLOUD_CONFIG_URL} #{CLOUD_CONFIG_KEY} #{CLOUD_CONFIG_TOKEN}`
at_exit do
File.delete cloud_config_file
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box_check_update = false
config.ssh.forward_agent = true
config.vm.define "devbox", primary: true do |devbox|
devbox.vm.hostname = "decapod"
devbox.vm.network "private_network", ip: "10.0.0.10"
devbox.vm.synced_folder ".", "/vagrant",
type: "nfs",
mount_options: ["rw", "vers=3", "noatime", "async"]
devbox.vm.provider "virtualbox" do |vb, override|
override.vm.box = "ubuntu/xenial64"
vb.gui = false
vb.memory = 4096
vb.cpus = 3
end
devbox.vm.provider "libvirt" do |lv, override|
override.vm.box = "yk0/ubuntu-xenial"
lv.nested = false
lv.memory = 4096
lv.cpus = 3
lv.cpu_mode = "host-passthrough"
lv.machine_virtual_size = 60
lv.disk_bus = "virtio"
lv.nic_model_type = "virtio"
end
if Vagrant.has_plugin?("vagrant-cachier")
devbox.cache.scope = :box
devbox.cache.enable :apt
devbox.cache.enable :apt_lists
devbox.cache.enable :npm
devbox.cache.synced_folder_opts = {
type: :nfs, mount_options: ['rw', 'vers=3', 'tcp', 'nolock']
}
else
print "vagrant-cachier plugin has not been found."
print "You can install it by `vagrant plugin install vagrant-cachier`"
end
devbox.vm.provision "ansible" do |ansible|
ansible.playbook = "devenv/devbox.yaml"
end
end
["node01", "node02", "node03", "node04", "node05"].each_with_index do |host, idx|
config.vm.define "#{host}", autostart: false do |client|
client.vm.hostname = "ceph-#{host}"
client.vm.network "private_network", ip: "10.0.0.2#{idx}"
client.vm.synced_folder ".", "/vagrant", disabled: true
# http://foo-o-rama.com/vagrant--stdin-is-not-a-tty--fix.html
client.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
client.vm.provision "set-utc-timezone", type: "shell" do |s|
s.privileged = true
s.inline = "ln -fs /usr/share/zoneinfo/UTC /etc/localtime && dpkg-reconfigure -f noninteractive tzdata"
end
# http://www.whiteboardcoder.com/2016/04/install-cloud-init-on-ubuntu-and-use.html
# https://raymii.org/s/tutorials/Automating_Openstack_with_Cloud_init_run_a_script_on_VMs_first_boot.html
client.vm.provision :ansible do |ansible|
ansible.playbook = File.join(
CURRENT_DIR, "infrastructure_playbooks", "server_discovery_playbook",
"playbook.yaml"
)
ansible.extra_vars = {
user_data: cloud_config_file,
cloud_init: false
}
end
client.vm.provider "virtualbox" do |vb, override|
override.vm.box = "ubuntu/xenial64"
vb.gui = false
vb.memory = 512
vb.cpus = 1
(0..2).each do |d|
disk_name = "#{host}-#{idx}-#{d}"
vb.customize ["createhd",
"--filename", disk_name,
"--size", "5000"] unless File.exist?("#{disk_name}.vdi")
vb.customize ["storageattach", :id,
'--storagectl', "SATAController",
"--port", 3 + d,
"--device", 0,
"--type", "hdd",
"--medium", "#{disk_name}.vdi"]
end
end
client.vm.provider "libvirt" do |lv, override|
override.vm.box = "yk0/ubuntu-xenial"
lv.nested = false
lv.memory = 512
lv.cpus = 1
lv.cpu_mode = "host-passthrough"
lv.disk_bus = "virtio"
lv.nic_model_type = "virtio"
5.times do
lv.storage :file, :size => "5G"
lv.storage :file, :size => "1G"
end
end
end
end
end