-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
172 lines (146 loc) · 5.56 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# frozen_string_literal: true
# -*- mode: ruby -*-
# vi: set ft=ruby :
##############################################################################
# Copyright (c)
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
no_proxy = ENV['NO_PROXY'] || ENV['no_proxy'] || '127.0.0.1,localhost'
(1..254).each do |i|
no_proxy += ",10.0.2.#{i}"
end
# rubocop:disable Metrics/BlockLength
Vagrant.configure('2') do |config|
# rubocop:enable Metrics/BlockLength
config.vm.provider :libvirt
config.vm.provider :virtualbox
config.vm.box = 'generic/ubuntu2204'
config.vm.box_check_update = false
%i[virtualbox libvirt].each do |provider|
config.vm.provider provider do |p|
p.cpus = 1
p.memory = 1024
end
end
# Configure DNS resolver
config.vm.provision 'shell', privileged: false, inline: <<-SHELL
if command -v systemd-resolve && sudo systemd-resolve --status --interface eth0; then
sudo systemd-resolve --interface eth0 --set-dns 1.1.1.1 --flush-caches
sudo systemd-resolve --status --interface eth0
fi
if [ -f /etc/netplan/01-netcfg.yaml ]; then
sudo sed -i "s/addresses: .*/addresses: [1.1.1.1, 8.8.8.8, 8.8.4.4]/g" /etc/netplan/01-netcfg.yaml
sudo netplan apply
fi
SHELL
config.vm.provider 'virtualbox' do |v|
v.gui = false
v.customize ['modifyvm', :id, '--nictype1', 'virtio', '--cableconnected1', 'on']
v.customize ['modifyvm', :id, '--nictype2', 'virtio', '--cableconnected2', 'on']
end
config.vm.provider :libvirt do |v|
v.random_hostname = true
v.management_network_address = '10.0.2.0/24'
v.management_network_name = 'administration'
v.cpu_mode = 'host-passthrough'
v.memorybacking :access, mode: 'shared'
end
if !ENV['http_proxy'].nil? && !ENV['https_proxy'].nil? && Vagrant.has_plugin?('vagrant-proxyconf')
config.proxy.http = ENV['http_proxy'] || ENV['HTTP_PROXY'] || ''
config.proxy.https = ENV['https_proxy'] || ENV['HTTPS_PROXY'] || ''
config.proxy.no_proxy = no_proxy
config.proxy.enabled = { docker: false }
end
config.vm.define :pxe_server do |pxe_server|
pxe_server.vm.hostname = 'pxe-server'
pxe_server.vm.synced_folder './pxe_server/', '/vagrant'
pxe_server.vm.provider :libvirt do |_v, override|
override.vm.synced_folder './pxe_server/', '/vagrant', type: 'virtiofs'
end
pxe_server.vm.network :private_network,
ip: '10.11.0.2',
virtualbox__intnet: 'pxe_network',
libvirt__network_name: 'pxe_network',
libvirt__dhcp_enabled: false
pxe_server.vm.provision 'shell', privileged: false, inline: <<-SHELL
set -o errexit
set -o pipefail
cd /vagrant
./deploy_tftp.sh | tee ~/deploy_tftp.log
./deploy_dhcp.sh | tee ~/deploy_dhcp.log
sudo nmap --script broadcast-dhcp-discover -e eth1
./deploy_pxe.sh | tee ~/deploy_pxe.log
SHELL
end
config.vm.define :bifrost do |bifrost|
bifrost.vm.hostname = 'bifrost'
bifrost.vm.synced_folder './bifrost/', '/vagrant'
bifrost.vm.provider :libvirt do |_v, override|
override.vm.synced_folder './bifrost/', '/vagrant', type: 'virtiofs'
end
bifrost.vm.network :private_network,
ip: '10.11.0.3',
virtualbox__intnet: 'pxe_network',
libvirt__network_name: 'pxe_network',
libvirt__dhcp_enabled: false
bifrost.vm.provision 'shell', privileged: false do |sh|
sh.env = {
BIFROST_PXE_NIC: 'eth0'
}
sh.inline = <<~SHELL
set -o errexit
set -o pipefail
cd /vagrant
./deploy.sh | tee ~/deploy.log
SHELL
end
end
config.vm.define :tinkerbell do |tinkerbell|
tinkerbell.vm.hostname = 'tinkerbell'
tinkerbell.vm.synced_folder './tinkerbell/', '/vagrant'
tinkerbell.vm.provider :libvirt do |_v, override|
override.vm.synced_folder './tinkerbell/', '/vagrant', type: 'virtiofs'
end
tinkerbell.vm.network :private_network,
ip: '10.11.0.4',
virtualbox__intnet: 'pxe_network',
libvirt__network_name: 'pxe_network',
libvirt__dhcp_enabled: false
tinkerbell.vm.provision 'shell', privileged: false, inline: <<-SHELL
set -o errexit
set -o pipefail
cd /vagrant
./install.sh | tee ~/install.log
./setup.sh | tee ~/setup.log
./deploy.sh | tee ~/deploy.log
SHELL
end
config.vm.define :node, autostart: false do |node|
node.vm.network :private_network,
mac: '000000000002',
virtualbox__intnet: 'pxe_network',
libvirt__network_name: 'pxe_network'
%i[virtualbox libvirt].each do |provider|
node.vm.provider provider do |p|
p.memory = 512
end
end
node.vm.provider :libvirt do |lv, override|
lv.boot 'network'
lv.mgmt_attach = false
override.vm.box = nil
lv.storage :file, size: '40G'
end
node.vm.provider :virtualbox do |vb|
vb.gui = true
vb.customize [
'modifyvm', :id, '--boot1', 'net', '--boot2', 'none',
'--boot3', 'none', '--boot4', 'none'
]
vb.customize ['modifyvm', :id, '--nic1', 'none']
end
end
end