Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Vagrant creates a development environment using VirtualBox and then provisions it using ansible. As part of the provisioning, ansible runs a reboot and then waits for SSH to come back up. This works as expected but because the vagrant machine is not being started from a "vagrant up" command the synced folders are not mounted properly when the box comes back up from the reboot.

Running "vagrant reload" fixes the machine and mounts the shares again.

Is there a way of either telling vagrant to reload the server or to do all the bits 'n bobs that vagrant would have done after a manual restart?

Simply running "sudo reboot" when SSH-ed into the vagrant box also produces the same problem.

like image 233
Max Avatar asked May 27 '14 16:05

Max


People also ask

How do you sync vagrant?

Vagrant automatically syncs files to and from the guest machine. This way you can edit files locally and run them in your virtual development environment. By default, Vagrant shares your project directory (the one containing the Vagrantfile) to the /vagrant directory in your guest machine.

How do I reboot my vagrant machine?

Command: vagrant reload [name|id] The configured provisioners will not run again, by default. You can force the provisioners to re-run by specifying the --provision flag.

Where are vagrant files?

Windows: C:/Users/USERNAME/. vagrant. d/boxes.

What is vagrant provision?

Provisioners in Vagrant allow you to automatically install software, alter configurations, and more on the machine as part of the vagrant up process. This is useful since boxes typically are not built perfectly for your use case.


1 Answers

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.

like image 63
Romain Komorn Avatar answered Sep 21 '22 07:09

Romain Komorn