forked from openSUSE/vagrant-ceph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
152 lines (116 loc) · 4.48 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
# -*- mode: ruby -*- # vi: set ft=ruby :
require 'yaml'
require 'pp'
### Not working within Vagrant ###
# require 'archive/tar/minitar'
require_relative 'lib/settings.rb'
require_relative 'lib/hosts.rb'
require_relative 'lib/provisions.rb'
config_dir = File.expand_path File.dirname(__FILE__)
config_file = File.join(config_dir, 'config.yml')
config = YAML.load_file(config_file)
# Check that the user has an ssh key
Vagrant::Hosts::check_for_ssh_keys
### take BOX from the enviroment ###
BOX = ENV.has_key?('BOX') ? ENV['BOX'] : 'virt-appl/openSUSE-Leap-15.1'
# Set BOX to one of 'Tumbleweed', 'SLE-12'
#BOX = 'SLE12-SP2-migration'
#BOX = 'SLE12-SP3-qa'
#BOX = 'SUSE/SLE-12-SP3'
#BOX = 'SUSE/SLE-15-SP1'
#BOX = 'SUSE/SLE-15-SP2'
#BOX = 'opensuse/Tumbleweed.x86_64'
# Set INSTALLATION to one of 'ceph-deploy', 'salt'
INSTALLATION = 'salt'
# Set CONFIGURATION to one of 'default', 'small', 'iscsi' or 'economical'
#CONFIGURATION = 'default'
CONFIGURATION = 'tiny'
#CONFIGURATION = 'dataonmon'
raise "Box #{BOX} missing from config.yml" unless config[BOX]
raise "Installation #{INSTALLATION} missing for box #{BOX} from config.yml" unless config[BOX][INSTALLATION]
raise "Configuration #{CONFIGURATION} missing from config.yml" unless config[CONFIGURATION]
# Set PREFIX for additional sets of VMs in libvirt from a separate directory
# (e.g. vagrant-ceph is default, vsm is another git clone with PREFIX='v'
# hostnames will be 'vadmin', 'vmon1', etc. Both sets use same address range
# and cannot run simultaneously. Each set will consume disk space. )
PREFIX = ''
# Generates a hosts file
if (INSTALLATION == 'salt') then
hosts = Vagrant::Hosts.new(config[CONFIGURATION]['nodes'],
selected = 'public', domain='ceph',
aliases={ 'admin' => 'salt' })
elsif (INSTALLATION == 'openattic') then
hosts = Vagrant::Hosts.new(config[CONFIGURATION]['nodes'],
selected = 'public', domain='ceph')
else
hosts = Vagrant::Hosts.new(config[CONFIGURATION]['nodes'])
end
def provisioned?(vm_name='default', provider='libvirt')
File.exist?(".vagrant/machines/#{vm_name}/#{provider}/action_provision")
end
def provisioning(hosts, node, config, name)
# Update /etc/hosts on each node
hosts.update(node)
# Allow passwordless root access between nodes
keys = Vagrant::Keys.new(node, config[CONFIGURATION]['nodes'].keys)
if (name == 'admin') then
# puts "authorize dummy"
keys.authorize
end
# Add missing repos
repos = Vagrant::Repos.new(node, config[BOX][INSTALLATION]['repos'])
if ENV.has_key?("CLEAN_ZYPPER_REPOS") or !provisioned?(name)
repos.clean
end
repos.add
#
# Add SUSEConnect repos
suseconnect = Vagrant::SUSEConnect.new(node, config[BOX][INSTALLATION]['register'])
suseconnect.add
# Copy custom files
files = Vagrant::Files.new(node, INSTALLATION, name,
config[BOX][INSTALLATION]['files'], BOX, CONFIGURATION)
files.copy
# Install additional/unique packages
pkgs = Vagrant::Packages.new(node, name,
config[BOX][INSTALLATION]['packages'])
pkgs.install
# Run commands
commands = Vagrant::Commands.new(node, name,
config[BOX][INSTALLATION]['commands'])
commands.run
end
Vagrant.configure("2") do |vconfig|
vconfig.vm.box = BOX
# workaround to skip key replacement, as it could hang with vagrant 1.8.7
vconfig.ssh.insert_key = false
# Keep admin at the end for provisioning
nodes = config[CONFIGURATION]['nodes'].keys.reject{|i| i == 'admin'}
nodes.each do |name|
vm_name = PREFIX + name
vconfig.vm.define vm_name do |node|
common_settings(node, config, name)
node.vm.provider :libvirt do |l|
libvirt_settings(l, config, name)
end
node.vm.provider :virtualbox do |vb|
virtbox_settings(vb, config, name)
end
provisioning(hosts, node, config, name)
end
end
# Appending admin to the nodes array does *not* guarantee that admin
# will provision last
name = "admin"
vm_name = PREFIX + "admin"
vconfig.vm.define vm_name do |node|
common_settings(node, config, name)
node.vm.provider :libvirt do |l|
libvirt_settings(l, config, name)
end
node.vm.provider :virtualbox do |vb|
virtbox_settings(vb, config, name)
end
provisioning(hosts, node, config, name)
end
end