forked from harvester/ipxe-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
108 lines (92 loc) · 3.96 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
# vi: set ft=ruby ts=2 :
require 'yaml'
VAGRANTFILE_API_VERSION = "2"
# check for required plugins
_required_plugins_list = %w{vagrant-libvirt}
exit(1) unless _required_plugins_list.all? do |plugin|
Vagrant.has_plugin?(plugin) || (
STDERR.puts "Required plugin '#{plugin}' is missing; please install using:"
STDERR.puts " % vagrant plugin install #{plugin}"
false
)
end
# ensure libvirt is the default provider in case the vagrant box config
# doesn't specify it
ENV['VAGRANT_DEFAULT_PROVIDER'] = "libvirt"
@root_dir = File.dirname(File.expand_path(__FILE__))
@settings = YAML.load_file(File.join(@root_dir, "settings.yml"))
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# continerd is taking more than 60 seconds to shutdown in SUSE platforms
# so increase the timeout to 120 seconds
config.vm.graceful_halt_timeout = 120
# PXE Server
config.vm.define :pxe_server do |pxe_server|
pxe_server.vm.box = 'generic/debian10'
pxe_server.vm.hostname = 'pxe-server'
pxe_server.vm.network 'private_network',
ip: @settings['harvester_network_config']['dhcp_server']['ip'],
libvirt__network_name: 'harvester',
# don't enable DHCP as this node will have it's now DHCP server for iPXE
libvirt__dhcp_enabled: false
pxe_server.vm.provider :libvirt do |libvirt|
libvirt.cpu_mode = 'host-passthrough'
libvirt.memory = '1024'
libvirt.cpus = '1'
end
pxe_server.vm.provision :ansible do |ansible|
ansible.playbook = 'ansible/setup_pxe_server.yml'
ansible.extra_vars = {
settings: @settings
}
end
end
# Harvester
cluster_node_index = @settings['harvester_cluster_nodes'] - 1
(0..cluster_node_index).each do |node_number|
vm_name = "harvester-node-#{node_number}"
config.vm.define vm_name, autostart: false do |harvester_node|
harvester_node.vm.hostname = "harvester-node-#{node_number}"
harvester_node.vm.network 'private_network',
libvirt__network_name: 'harvester',
mac: @settings['harvester_network_config']['cluster'][node_number]['mac']
harvester_node.vm.provider :libvirt do |libvirt|
libvirt.cpu_mode = 'host-passthrough'
libvirt.memory = @settings['harvester_network_config']['cluster'][node_number].key?('memory') ? @settings['harvester_network_config']['cluster'][node_number]['memory'] : @settings['harvester_node_config']['memory']
libvirt.cpus = @settings['harvester_network_config']['cluster'][node_number].key?('cpu') ? @settings['harvester_network_config']['cluster'][node_number]['cpu'] : @settings['harvester_node_config']['cpu']
libvirt.storage :file,
size: @settings['harvester_network_config']['cluster'][node_number].key?('disk_size') ? @settings['harvester_network_config']['cluster'][node_number]['disk_size'] : @settings['harvester_node_config']['disk_size'],
type: 'qcow2',
bus: 'virtio',
device: 'vda'
boot_network = {'network' => 'harvester'}
libvirt.boot 'hd'
libvirt.boot boot_network
# NOTE: default to UEFI boot. Comment this out for legacy BIOS.
libvirt.loader = '/usr/share/qemu/OVMF.fd'
libvirt.nic_model_type = 'e1000'
end
end
end
# Rancher
if @settings['rancher_config']['enabled']
config.vm.define :rancher do |rancher|
rancher.vm.box = 'generic/debian10'
rancher.vm.hostname = 'rancher'
rancher.vm.network 'private_network',
ip: @settings['rancher_config']['ip'],
libvirt__network_name: 'harvester',
libvirt__dhcp_enabled: false
rancher.vm.provider :libvirt do |libvirt|
libvirt.cpu_mode = 'host-passthrough'
libvirt.cpus = @settings['rancher_config']['cpu']
libvirt.memory = @settings['rancher_config']['memory']
end
rancher.vm.provision :ansible do |ansible|
ansible.playbook = 'ansible/setup_rancher.yml'
ansible.extra_vars = {
settings: @settings
}
end
end
end
end