forked from kairen/kube-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
117 lines (100 loc) · 3.19 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
require "yaml"
require "fileutils"
Vagrant.require_version ">= 1.7.0"
CONFIG = File.expand_path("./hack/.config.rb")
if File.exist?(CONFIG)
require CONFIG
end
$os_image = (ENV['OS_IMAGE'] || "ubuntu16").to_sym
$provider = (ENV['PROVIDER'] || "virtualbox").to_sym
$auto_deploy = (ENV['DEPLOY']|| "true").to_sym
def set_vbox(vb, config)
vb.gui = false
vb.memory = $system_memory
vb.cpus = $system_vcpus
case $os_image
when :centos7
config.vm.box = "bento/centos-7.3"
when :ubuntu16
config.vm.box = "bento/ubuntu-16.04"
end
end
def set_libvirt(lv, config)
lv.nested = true
lv.volume_cache = 'none'
lv.uri = 'qemu+unix:///system'
lv.memory = $system_memory
lv.cpus = $system_vcpus
case $os_image
when :centos7
config.vm.box = "centos/7"
when :ubuntu16
config.vm.box = "yk0/ubuntu-xenial"
end
end
def set_hyperv(hv, config)
hv.memory = $system_memory
hv.cpus = $system_vcpus
case $os_image
when :centos7
config.vm.box = "generic/centos7"
config.vm.provision "shell", inline: "sudo yum install -y python"
when :ubuntu16
config.vm.box = "generic/ubuntu1604"
config.vm.provision "shell", inline: "sudo apt-get update && sudo apt-get install -y python"
end
end
Vagrant.configure("2") do |config|
config.vm.provider "hyperv"
config.vm.provider "virtualbox"
config.vm.provider "libvirt"
config.vm.provision "shell", inline: "sudo swapoff -a"
if $provider.to_s != 'hyperv'
config.vm.provision "shell", inline: "sudo cp /vagrant/hosts /etc/"
end
count = $net_count
(1..($master_count + $node_count)).each do |mid|
name = (mid <= $master_count) ? "k8s-m" : "k8s-n"
id = (mid <= $master_count) ? mid : (mid - $master_count)
config.vm.define "#{name}#{id}" do |n|
n.vm.hostname = "#{name}#{id}"
ip_addr = "#{$private_subnet}.#{count}"
n.vm.network :private_network, ip: "#{ip_addr}", auto_config: true
if $bridge_enable && $bridge_eth.to_s != ''
n.vm.network "public_network", bridge: $bridge_eth
end
# Configure virtualbox provider
n.vm.provider :virtualbox do |vb, override|
vb.name = "#{n.vm.hostname}"
set_vbox(vb, override)
end
# Configure libvirt provider
n.vm.provider :libvirt do |lv, override|
lv.host = "#{n.vm.hostname}"
set_libvirt(lv, override)
end
# Configure hyperv provider
n.vm.provider :hyperv do |hv, override|
hv.vmname = "#{n.vm.hostname}"
set_hyperv(hv, override)
end
count += 1
if mid == ($master_count + $node_count) && $provider.to_s != 'hyperv' && $auto_deploy.to_s == 'true'
n.vm.provision "cluster", type: "ansible" do |ansible|
ansible.playbook = "cluster.yml"
ansible.inventory_path = "./inventory/hosts.ini"
ansible.become = true
ansible.limit = "all"
ansible.host_key_checking = false
end
n.vm.provision "addon", type: "ansible" do |ansible|
ansible.playbook = "addons.yml"
ansible.inventory_path = "./inventory/hosts.ini"
ansible.become = true
ansible.limit = "all"
ansible.host_key_checking = false
end
end
end
end
end