Я пытаюсь создать виртуальную машину с vagrant с несколькими дисками, но я хочу, чтобы vagrantfile использовал цикл для их создания. Vagrant неправильно обрабатывает петли, поскольку кажется, что он удваивает или удваивает циклЗатем Vagrant дает сбой, поскольку он уже создал disk1.vdi
Предупреждение: я не специалист по Ruby ...
Я пытался использовать массивы и метод rue's .each. Попробовал цикл пока. Все терпят неудачу с одной и той же проблемой.
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.provider "virtualbox" do |v|
Drives = [1,2,3,4,5]
Drives.each do |hd|
puts "harddrive #{hd}"
v.customize ['createhd', '--filename', "./disk#{hd}.vdi",'--variant', 'Fixed', '--size', 20 * 1024]
v.customize ['storageattach', :id, '--storagectl', 'IDE', '--device', hd+1, '--type', 'hdd', '--medium', "./disk#{hd}.vdi"]
end
end
end
Я ожидаю, что виртуальный компьютер с 5 + 1 дисками
получит
$ vagrant up
harddrive 1
harddrive 2
harddrive 3
harddrive 4
harddrive 5
/home/brian/projects/centos/Vagrantfile:7: warning: already initialized constant Drives
/home/brian/projects/centos/Vagrantfile:7: warning: previous definition of Drives was here
harddrive 1
harddrive 2
harddrive 3
harddrive 4
harddrive 5
/home/brian/projects/centos/Vagrantfile:7: warning: already initialized constant Drives
/home/brian/projects/centos/Vagrantfile:7: warning: previous definition of Drives was here
harddrive 1
harddrive 2
harddrive 3
harddrive 4
harddrive 5
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'centos/7' version '1905.1' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
A customization command failed:
["createhd", "--filename", "./disk1.vdi", "--variant", "Fixed", "--size", 20480]
The following error was experienced:
#<Vagrant::Errors::VBoxManageError: There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["createhd", "--filename", "./disk1.vdi", "--variant", "Fixed", "--size", "20480"]
Stderr: 0%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage: error: Failed to create medium
VBoxManage: error: Could not create the medium storage unit '/home/brian/projects/centos/disk1.vdi'.
VBoxManage: error: VDI: cannot create image '/home/brian/projects/centos/disk1.vdi' (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium
VBoxManage: error: Context: "RTEXITCODE handleCreateMedium(HandlerArg*)" at line 462 of file VBoxManageDisk.cpp
>
Please fix this customization and try again.