-
Notifications
You must be signed in to change notification settings - Fork 5
/
Vagrantfile
192 lines (183 loc) · 8.43 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# configure the virtual machines network to use an already configured bridge.
# NB this must be used for connecting to the external switch.
$provisioner_bridge_name = 'br-rpi'
$provisioner_ip_address = '10.3.0.2'
# uncomment the next two lines to configure the virtual machines network
# to use a new private network that is only available inside the host.
# NB this must be used for NOT connecting to the external switch.
#$provisioner_bridge_name = nil
#$provisioner_ip_address = '10.11.12.2'
# to make sure the nodes are created sequentially, we
# have to force a --no-parallel execution.
ENV['VAGRANT_NO_PARALLEL'] = 'yes'
# enable typed triggers.
# NB this is needed to modify the libvirt domain scsi controller model to virtio-scsi.
ENV['VAGRANT_EXPERIMENTAL'] = 'typed_triggers'
require 'open3'
# get the docker hub auth from the host ~/.docker/config.json file.
def get_docker_hub_auth
config_path = File.expand_path '~/.docker/config.json'
return nil unless File.exists? config_path
config = JSON.load File.read(config_path)
return nil unless config.has_key?('auths') && config['auths'].has_key?('https://index.docker.io/v1/')
config['auths']['https://index.docker.io/v1/']['auth']
end
DOCKER_HUB_AUTH = get_docker_hub_auth
Vagrant.configure('2') do |config|
config.vm.box = 'ubuntu-20.04-amd64'
config.vm.provider :libvirt do |lv, config|
lv.memory = 4*1024
lv.cpus = 4
lv.cpu_mode = 'host-passthrough'
# lv.nested = true
lv.keymap = 'pt'
lv.disk_bus = 'scsi'
lv.disk_device = 'sda'
lv.disk_driver :discard => 'unmap', :cache => 'unsafe'
# NB vagrant-libvirt does not yet support urandom; but since tinkerbell
# built iPXE takes too much time to leave the "Initialising devices"
# phase we modify this to urandom in the trigger bellow.
lv.random :model => 'random'
config.vm.synced_folder '.', '/vagrant', type: 'nfs', nfs_version: '4.2', nfs_udp: false
config.vm.synced_folder "#{ENV['HOME']}/.vagrant.d/boxes", '/vagrant-boxes', mount_options: ['ro'], type: 'nfs', nfs_version: '4.2', nfs_udp: false
config.trigger.before :'VagrantPlugins::ProviderLibvirt::Action::StartDomain', type: :action do |trigger|
trigger.ruby do |env, machine|
# modify the scsi controller model to virtio-scsi.
# see https://github.com/vagrant-libvirt/vagrant-libvirt/pull/692
# see https://github.com/vagrant-libvirt/vagrant-libvirt/issues/999
stdout, stderr, status = Open3.capture3(
'virt-xml', machine.id,
'--edit', 'type=scsi',
'--controller', 'model=virtio-scsi')
if status.exitstatus != 0
raise "failed to run virt-xml to modify the scsi controller model. status=#{status.exitstatus} stdout=#{stdout} stderr=#{stderr}"
end
# modify the random model to use the urandom backend device.
stdout, stderr, status = Open3.capture3(
'virt-xml', machine.id,
'--edit',
'--rng', '/dev/urandom')
if status.exitstatus != 0
raise "failed to run virt-xml to modify the random backend device. status=#{status.exitstatus} stdout=#{stdout} stderr=#{stderr}"
end
end
end
end
config.vm.define :provisioner do |config|
config.vm.hostname = 'provisioner'
if $provisioner_bridge_name
config.vm.network :public_network,
ip: $provisioner_ip_address,
dev: $provisioner_bridge_name,
mode: 'bridge',
type: 'bridge'
else
config.vm.network :private_network,
ip: $provisioner_ip_address,
libvirt__dhcp_enabled: false,
libvirt__forward_mode: 'none'
end
config.trigger.before :up do |trigger|
trigger.run = {
inline: '''bash -euc \'
file_paths=(
~/.ssh/id_rsa.pub
../tinkerbell-debian-osie/tinkerbell-debian-osie-amd64.iso
../tinkerbell-debian-osie/tinkerbell-debian-osie-arm64.iso
)
for file_path in "${file_paths[@]}"; do
if [ -f $file_path ]; then
mkdir -p tmp
rsync $file_path tmp
fi
done
\'
'''
}
end
config.vm.provision :shell, path: 'provision-base.sh'
config.vm.provision :shell, path: 'provision-docker.sh'
config.vm.provision :shell, path: 'provision-docker-hub-auth.sh', env: {'DOCKER_HUB_AUTH' => DOCKER_HUB_AUTH}
config.vm.provision :shell, path: 'provision-docker-compose.sh'
config.vm.provision :shell, path: 'provision-portainer.sh'
config.vm.provision :shell, path: 'provision-loki.sh'
config.vm.provision :shell, path: 'provision-grafana.sh', args: [$provisioner_ip_address]
config.vm.provision :shell, path: 'provision-meshcommander.sh'
config.vm.provision :shell, path: 'provision-go.sh'
config.vm.provision :shell, path: 'provision-tinkerbell.sh', args: [$provisioner_ip_address]
config.vm.provision :shell, path: 'provision-docker-buildx.sh'
config.vm.provision :shell, path: 'provision-debian-boots.sh'
config.vm.provision :shell, path: 'provision-debian-osie.sh'
config.vm.provision :shell, path: 'provision-tinkerbell-tink.sh'
config.vm.provision :shell, path: 'provision-nfs-server.sh'
config.vm.provision :shell, path: 'actions/provision.sh'
config.vm.provision :shell, path: 'templates/provision.sh'
config.vm.provision :shell, path: 'workers/provision.sh'
config.vm.provision :shell, name: 'Summary', path: 'summary.sh', run: 'always'
end
['bios', 'uefi'].each_with_index do |firmware, i|
config.vm.define firmware do |config|
config.vm.box = nil
if $provisioner_bridge_name
config.vm.network :public_network,
dev: $provisioner_bridge_name,
mac: "08002700000#{i+1}",
mode: 'bridge',
type: 'bridge',
auto_config: false
else
config.vm.network :private_network,
# NB this ip is not really used by the VM; its used by
# vagrant-libvirt to find the network to which it
# will attach this VM to.
ip: $provisioner_ip_address,
mac: "08002700000#{i+1}",
auto_config: false
end
config.vm.provider :libvirt do |lv, config|
lv.loader = '/usr/share/ovmf/OVMF.fd' if firmware == 'uefi'
lv.memory = 4*1024
lv.boot 'hd'
lv.boot 'network'
lv.mgmt_attach = false
lv.graphics_type = 'spice'
lv.video_type = 'qxl'
lv.input :type => 'tablet', :bus => 'usb'
lv.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
lv.channel :type => 'spicevmc', :target_name => 'com.redhat.spice.0', :target_type => 'virtio'
# set some BIOS settings that will help us identify this particular machine.
#
# QEMU | Linux
# --------------------+----------------------------------------------
# type=1,manufacturer | /sys/devices/virtual/dmi/id/sys_vendor
# type=1,product | /sys/devices/virtual/dmi/id/product_name
# type=1,version | /sys/devices/virtual/dmi/id/product_version
# type=1,serial | /sys/devices/virtual/dmi/id/product_serial
# type=1,sku | dmidecode
# type=1,uuid | /sys/devices/virtual/dmi/id/product_uuid
# type=3,manufacturer | /sys/devices/virtual/dmi/id/chassis_vendor
# type=3,family | /sys/devices/virtual/dmi/id/chassis_type
# type=3,version | /sys/devices/virtual/dmi/id/chassis_version
# type=3,serial | /sys/devices/virtual/dmi/id/chassis_serial
# type=3,asset | /sys/devices/virtual/dmi/id/chassis_asset_tag
[
'type=1,manufacturer=your vendor name here',
'type=1,product=your product name here',
'type=1,version=your product version here',
"type=1,serial=your product serial number here #{i+1}",
'type=1,sku=your product SKU here',
"type=1,uuid=00000000-0000-4000-8000-00000000000#{i+1}",
'type=3,manufacturer=your chassis vendor name here',
#'type=3,family=1', # TODO why this does not work on qemu from ubuntu 18.04?
'type=3,version=your chassis version here',
"type=3,serial=your chassis serial number here #{i+1}",
"type=3,asset=your chassis asset tag here #{i+1}",
].each do |value|
lv.qemuargs :value => '-smbios'
lv.qemuargs :value => value
end
lv.storage :file, :size => '65G', :device => 'sda', :bus => 'scsi', :discard => 'unmap', :detect_zeroes => 'unmap', :cache => 'unsafe'
end
end
end
end