-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
96 lines (78 loc) · 2.65 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
hosts = {
'master' => {
'count' => 3,
'ip_prefix' => '192.168.33.1',
'node_ip_prefix' => '10.0.33.1'
},
'node' => {
'count' => 1,
'ip_prefix' => '192.168.33.2',
'node_ip_prefix' => '10.0.33.2'
}
}
inventory = File.open('vagrant_inventory', 'w')
# host section
hosts.each_pair do |type, data|
(1..data['count']).each do |i|
inventory.puts("#{type}#{i} ansible_host=#{data['ip_prefix']}#{i} node_ip=#{data['node_ip_prefix']}#{i} ansible_ssh_private_key_file=.vagrant/machines/#{type}#{i}/virtualbox/private_key")
end
end
# group section
hosts.each_pair do |type, data|
inventory.puts("[#{type}]")
(1..data['count']).each do |i|
inventory.puts("#{type}#{i}")
end
end
inventory.close
Vagrant.configure("2") do |config|
if ARGV[1] == 'base'
config.vm.box = "hashicorp/bionic64"
config.vm.define "base" do |machine|
machine.vm.hostname = "base"
machine.vm.provider "virtualbox" do |vb|
vb.cpus = 2
vb.memory = 2048
end
end
config.vm.post_up_message = "vagrant package base --output k8s.box && vagrant box add k8s-base k8s.box -f && vagrant destroy base -f"
else
config.vm.box = "k8s-base"
hosts.each_pair do |type, data|
(1..data['count']).each do |i|
config.vm.define "#{type}#{i}" do |machine|
machine.vm.network "private_network", ip: "#{data['ip_prefix']}#{i}"
# Disable auto_config for this private_network for setting the right ip for the right interface
machine.vm.network "private_network", ip: "#{data['node_ip_prefix']}#{i}", auto_config: false
machine.vm.hostname = "#{type}#{i}"
machine.vm.provider "virtualbox" do |vb|
vb.cpus = 2
vb.memory = 3000
file_to_disk = "./.vagrant/disk-#{type}#{i}.vmdk"
unless File.exist?(file_to_disk)
vb.customize [ "createmedium", "disk", "--filename", file_to_disk, "--format", "vmdk", "--size", 40 * 1024 ]
end
vb.customize [ "storageattach", :id, "--storagectl", "SATA Controller", "--port", 1, "--device", 0, "--type", "hdd", "--medium", file_to_disk ]
end
end
end
end
end
config.vm.provision "ansible" do |ansible|
ansible.verbose = "vv"
ansible.playbook = "k8s/playbook.yml"
# Use tag "base" based on ARGV
if ARGV[1] == 'base'
ansible.tags = "base"
# Needed for installing everything
ansible.groups = {
"master" => ["base"]
}
else
ansible.inventory_path = "vagrant_inventory"
ansible.skip_tags = "base"
end
end
end