Reputation: 7330
I need to create a simple script (Windows .bat) that will provision or up a box.
Not much experience with .bat files, so this is what I have so far:
Edited thanks to Greg Hewgill
cd C:\vagrant-box\
call vagrant-up.bat
if errorlevel 1 call vagrant-provision.bat
The .bat files call
ed in the script just contain one line: vagrant up
and vagrant reload
, respectively.
When the vagrant box is down, then vagrant up runs successfully. When up, I encounter an error with vagrant up (which I expect) but the whole batch file dies there. ErrorLevel
doesn't appear to do anything.
Here is the error if it makes a difference
Bringing machine 'default' up with 'virtualbox' provider...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["list", "hostonlyifs"]
Stderr: VBoxManage.exe: error: Failed to create the VirtualBox object!
VBoxManage.exe: error: Code CO_E_SERVER_EXEC_FAILURE (0x80080005) - Server execution failed (extend)
VBoxManage.exe: error: Most likely, the VirtualBox COM server is not running or failed to start.
I want to emphasize I don't care about the error per se. It works when the box is not running, so it's fine. I just want to capture or ignore it, and move to the next command.
Upvotes: 1
Views: 3073
Reputation: 6195
Please post your vagrant-up.bat.
Also, try either this:
vagrant up --debug
and/or
VAGRANT_LOG=debug vagrant <action>
To get more detais about the COM/VBox issue.
Upvotes: 1
Reputation: 10536
vagrant up
exits with code 0 even if the machine is already running.
But you don't have to bother with exit codes, you can just run:
vagrant provision && vagrant up
And you should cover both cases. If the guest is not running, vagrant provision
will gracefully fail and vagrant up
will succeed, and vice versa.
Upvotes: 2