vagrant-reload icon indicating copy to clipboard operation
vagrant-reload copied to clipboard

reload + vb.customize = sad

Open thenoid opened this issue 9 years ago • 6 comments

In my vagrant file i have something like this

diskpath="c:\\tmp\\"
srvname="somerandomstring"
file_to_disk="#{diskpath}#{srvname}.vdi"

    srv.vm.provider :virtualbox do |vb|
      unless File.exist?('file_to_disk')
        puts file_to_disk 
        vb.customize ['createhd', '--filename', file_to_disk, '--size', 100 * 1024]

      end
      vb.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
    end

    srv.vm.provision :shell, path: "scripts/proxy_setup.sh"
    srv.vm.provision :reload

Problem that i'm running into, is that when reload executes - it appears the value of the "File.exists?" isn't being re-evaluated, so the condition still returns false adn the createhd executes again, which errors out.

i've tested that if the file exists before hand, teh File.exists triggers, so i know my logic/paths aren't bad there. Definitely some interaction between reload + customizer

A customization command failed:

["createhd", "--filename", "c:\\tmp\\openshift-infra-ctp-rh7-x86_64.vdi", "--size", 102400]

  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", "c:\\tmp\\openshift-infra-ctp-rh7-x86_64.vdi", "--size", "102400"]

  Stderr: 0%...
  Progress state: VBOX_E_FILE_ERROR
  VBoxManage.exe: error: Failed to create medium
  VBoxManage.exe: error: Could not create the medium storage unit 'c:\tmp\openshift-infra-ctp rh7-x86_64.vdi'.
  VBoxManage.exe: error: VDI: cannot create image 'c:\tmp\openshift-infra-ctp-rh7-x86_64.vdi' (VERR_ALREADY_EXISTS)
  VBoxManage.exe: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium
  VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleCreateMedium(struct HandlerArg *)" at line 449 of file VBoxManageDisk.cpp
  >

  Please fix this customization and try again.

thenoid avatar Oct 01 '15 18:10 thenoid

The same problem here with virtualbox-5.0, Ubuntu 14.04, 3.13.0-85-generic, vagrant_1.8.1_x86_64.deb.

Virtualbox to 4.3.38r106717 reloads without errors. Interestingly the "puts" statement does not give any output when successfully reloading with virtualbox-4.3 so probably it's a wrong track.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.define "centos7" do |machine|
    machine.vm.box = "puppetlabs/centos-7.2-64-puppet"
    machine.vm.box_url = "puppetlabs/centos-7.2-64-puppet"
    machine.vm.provider "virtualbox" do |v|
      v.memory = 256
      v.cpus = 1
      disk = 'sdb.vdi'
      if !File.exist?(disk)
        puts disk
        v.customize ['createhd', '--filename', disk, '--size', 64, '--variant', 'Fixed']
        v.customize ['modifyhd', disk, '--type', 'writethrough']
      end
      v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 0, '--device', 1, '--type', 'hdd', '--medium', disk]
    end
  end
  config.vm.define "centos7" do |machine|
    machine.vm.provision :reload
  end
end

marcindulak avatar Apr 30 '16 14:04 marcindulak

I had a similar problem. For me the problem could be solved to shorten the file path ot the image. On Windows for example the maximum length of a file path is 260 chars.

frusswur avatar May 11 '16 12:05 frusswur

Reloading works fine on VirtualBox 4.3, because vboxmanage createhd returns 0 even if it failed: see output of vagrant up --debug.

marcinbarczynski avatar Nov 08 '16 10:11 marcinbarczynski

This is still a problem. And reverting to an old version of VirtualBox is not a good solution. Is there any way to have reload clear out the provider object or something?

an0t8 avatar Sep 18 '17 17:09 an0t8

This project is not maintained. Switch to https://github.com/vagrant-libvirt/vagrant-libvirt if you can, it does not seem to have such problems.

marcindulak avatar Sep 18 '17 19:09 marcindulak

On the eve to 2019 and the problem still persists. Just tested with Vagrant 2.2.2 and VBox 6. windows 10 1809 as host and Ubuntu 18.04 as guest.

I also tried many different variants of how to wrap that "pre boot customization" in various conditionals - but it seems like whenever the reload happens the vm is properly shutdown and then vagrant tries to do the "pre boot customizations" again while ignoring every conditional constructs around them.

Could this be an issue with the evaluation order of vagrant files?

I found a workaround...I extracted the vboxmanage createmedium disk command to a shell script and then call vagrant up. that way the provisioning works. I will try to augment the virtualbox providers customize command with some additional checks, like ignoring a given list of errors or something like that.

rubenst2013 avatar Dec 31 '18 08:12 rubenst2013