Synced folders lost when rebooting a Vagrant machine using the Ansible provisioner

There is no way for Vagrant to know that the machine is being rebooted during the provisioning.

If possible, the best would be to avoid rebooting here altogether. For example kernel updates should be already done when building the base box.

Another easy (but not very convenient) way is to handle it with log output or documentation, or with a wrapper script which invokes vagrant up && vagrant reload.

And finally, you could write a plugin which injects all the needed mounting etc. actions to Vagrant middleware stack after the provisioning, but you would still need to think how to let the plugin know that the machine has been booted. Other challenge is that this easily gets provider specific.


You should be able to add the filesystems to /etc/fstab to mount on boot.

Here's my example:

vagrant /vagrant    vboxsf  defaults    0   0
home_vagrant_src    /home/vagrant/src   vboxsf  defaults    0   0
home_vagrant_presenter-src  /home/vagrant/presenter-src vboxsf  defaults    0   0

Your vagrant directory should have a .vagrant hidden directory in it, and in there you should find a path to the "synced_folders" file (in my case: /vagrant/.vagrant/machines/default/virtualbox/synced_folders).

That file should help you figure out what the labels are and their mount points:

{"virtualbox":{"/home/vagrant/src":{"guestpath":"/home/vagrant/src","hostpath":"/home/rkomorn/src","disabled":false,"__vagrantfile":true},"/home/vagrant/presenter-src":{"guestpath":"/home/vagrant/presenter-src","hostpath":"/home/presenter/src","disabled":false,"__vagrantfile":true},"/vagrant":{"guestpath":"/vagrant","hostpath":"/home/rkomorn/vagrant","disabled":false,"__vagrantfile":true}}}

It's not the easiest to read but, using python terminology, the labels appear to be the inner dictionary's keys, with / translated to _ (eg: the /home/vagrant/presenter-src key became the home_vagrant_presenter-src label).

I'm actually not sure why vagrant doesn't just use /etc/fstab for shared folders but I'm guessing there's a good reason.