Hi,
I want to be able to conditionally add a controller to a VirtualBox VM using the cusotmize feature, as follows:
vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]
This works for first time boot, but errors out when reloading the VM without destroying it first. So far, the only workaround that seems to work is to test for the existence of a storage device that is attached to this controller (or, in fact, any VDI disk created by Vagrant using vbx.customize), so the logic looks something like this:
if not(File.exist?("#{vdisk_root}/disk1.vdi"))
vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]
end
However, the disk in this case is shared between two VMs, so if I provision the nodes one at a time, the first node will be created correctly, but the second node will not get the additional controller (because the VDI file exists), and the provisioning will fail. If I provision both nodes at once, there's no issue, which is okay as a workaround, but not ideal.
Is there a way to test whether or not the target VM has previously been provisioned or is a new install? I've tried some simple hacks to flag a build, but they don't work because of the "outside-in" flow of logic. I'm really trying to avoid having to write a plugin or some other invasive and high maintenance workaround, since I am new to Vagrant and to Ruby.
I'm really looking for something testable and reasonably portable that would only exist after a VM has been provisioned for the first time.
Any advice gratefully received.
Malcolm.