-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVagrantfile
68 lines (59 loc) · 2.01 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
node_configs = [
{role: 'master', qty: 1 },
{role: 'worker', qty: 3},
]
# Max instances per role. Used for spacing ip addresses
role_spacer = 10
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
# Deliberatly disabled as it is not needed. Change `disabled: true`
# to `disabled: false` if you would like to use NFS shares or you can
# change to some other vagrant share system.
config.vm.synced_folder ".",
"/vagrant",
type: "nfs",
nfs_udp: false,
disabled: true
config.vm.provider :libvirt do |libvirt|
libvirt.cpus = 2
libvirt.memory = 4096
libvirt.nested = true
libvirt.graphics_type = 'spice'
libvirt.video_type = 'virtio'
# Use QEMU system instead of session connection
libvirt.qemu_use_session = false
end
ansible_groups = {}
node_configs.each_with_index do |node_conf, i|
role_num = i+1 # dont want multiply by zero later
if node_conf[:qty] > role_spacer
puts "ERROR: Role #{node_conf[:role]} has 'qty' of #{node_conf[:qty]} greater than #{role_spacer} (role_spacer)"
abort
end
(1..(node_conf[:qty])).each do |node_num|
id = role_spacer*role_num+node_num
config.vm.define "#{node_conf[:role]}-#{id}" do |node|
hostname = "#{node_conf[:role]}-#{id}"
if ansible_groups.key?(node_conf[:role])
ansible_groups[node_conf[:role]] << hostname
else
ansible_groups[node_conf[:role]] = [hostname]
end
node.vm.hostname = hostname
node.vm.network "private_network", ip: "192.168.200.#{id}" #, libvirt__forward_mode: 'route'
node.vm.provision "shell", inline: 'sed -i "/$HOSTNAME/d" /etc/hosts'
if node_conf[:role].eql?('worker')
node.vm.provider :libvirt do |libvirt|
libvirt.storage :file, :size => '40G'
end
end
end
end
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/playbook.yml"
ansible.groups = ansible_groups
end
end