Idempotent / conditional vbx.customize ["storagectl"] ??

88 views
Skip to first unread message

Malcolm Cowe

unread,
May 9, 2017, 8:54:51 PM5/9/17
to Vagrant
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.

Alvaro Miranda Aguilera

unread,
May 10, 2017, 3:38:03 AM5/10/17
to vagra...@googlegroups.com
Hello
You can create a control file for each node, and use that for your work.

pseudo code.

if file doesn't exists
  do the sata thing
  create the file
end


in ruby would be.


unless File.file?("node1.txt")
  vbx.customize ["storagectl", :id, "--name", "SATAController", "--add", "sata"]
  File.open("node1.txt", "w") {|f| f.write("node1")}
end 

Alvaro.


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/79d89249-424f-4fa8-9621-9668a39a17a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Malcolm Cowe

unread,
May 10, 2017, 7:31:10 AM5/10/17
to Vagrant
Hi,

Thanks for the pointer. I had tried something similar, but using an "if" statement and found that the file was being created before the vbx.customize step was executed... I shall review and try your approach.

Malcolm.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.



--
Alvaro

Reply all
Reply to author
Forward
0 new messages