I'm using Vagrant on two machines (home and office) with my working directories stored in Dropbox. I regularly run into the pronblem:
The VirtualBox VM was created with a user that doesn't match the
current user running Vagrant. VirtualBox requires that the same user
be used to manage the VM that was created. Please re-run Vagrant with
that user. This is not a Vagrant issue.
This is easily solved, brute-force, by rm -rf .vagrant
, but I'd like to find a more elegant solution -- like an easily automated way to put the .vagrant
files elsewhere.
Update
Here's the scenario: a working directory shared between office and home machine via Dropbox.
vagrant up
on office machine, successfully.vagrant up
, saying the id
values aren't the same as when I created. (503 vs 501 in general)rm -rf .vagrant
and do vagrant up
again, successfully.Vagrant provides an environment variable for exactly this use case: VAGRANT_DOTFILE_PATH
See the documentation here:
https://www.vagrantup.com/docs/other/environmental-variables.html#vagrant_dotfile_path
VAGRANT_DOTFILE_PATH
VAGRANT_DOTFILE_PATH
can be set to change the directory where Vagrant stores VM-specific state, such as the VirtualBox VM UUID. By default, this is set to.vagrant
. If you keep your Vagrantfile in a Dropbox folder in order to share the folder between your desktop and laptop (for example), Vagrant will overwrite the files in this directory with the details of the VM on the most recently-used host. To avoid this, you could setVAGRANT_DOTFILE_PATH
to.vagrant-laptop
and.vagrant-desktop
on the respective machines. (Remember to update your.gitignore
!)