Search code examples
vagrantdropboxvagrantfile

Vagrant .vagrant file on Dropbox


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.

  1. I vagrant up on office machine, successfully.
  2. I shut down office machine and go home.
  3. I get the message about on vagrant up, saying the id values aren't the same as when I created. (503 vs 501 in general)
  4. I do rm -rf .vagrant and do vagrant up again, successfully.
  5. When I go back to the office, same problem.

Solution

  • 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 set VAGRANT_DOTFILE_PATH to .vagrant-laptop and .vagrant-desktop on the respective machines. (Remember to update your .gitignore!)