0

I'm trying to add add an additional synced folder besides the default /vagrant.

I've read the documentation which indicates that this should be as simple as:

config.vm.synced_folder "/path/to/somewhere/on/host", "/path/to/guest_directory", create: true

When I add this to my Vagrantfile and then reprovision it, the guest_directory folder shows up in the expected place on the host, but it's empty. And the folder in the guest OS is also empty... which breaks my site because those are the website files. Interestingly, if I remove that from the Vagrantfile and reprovision again, the files reappear in the guest OS where they were originally.

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu/xenial64"
  config.vm.network "private_network", ip: "192.168.33.99"

  # NEITHER OF THESE WORK...
  # config.vm.synced_folder "/Users/ESL/Sites/project/web__public_web", "/home/vagrant/web__public_web", create: true
  # config.vm.synced_folder "./web__public_web", "/home/vagrant/web__public_web", type: "rsync", rsync__args: ["--verbose", "--archive", "--delete", "-z"], create: true

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "2046"
  end

end

You can see that I've tried a two different type: options and got the same wrong result with both. I also tried placing a symlink to the project files inside /vagrant/ and that didn't work either. (The broken symlink showed up in the host os directory instead of the files I want to access)

Here are a couple more details about my setup, just in case they're relevant:

  • In the guest OS the project files live in /home/vagrant/web__public_web but the document root is /srv/www/... which contains a symlink pointing to the former path.
  • VirtualBox: Version 5.2.18 r124319 (Qt5.6.3)
  • Vagrant: v2.1.0
  • OSX: 10.13.6

What am I doing wrong?

emersonthis
  • 32,822
  • 59
  • 210
  • 375

2 Answers2

0

Each mount requires a unique id, if the box is already built you'll need to rebuild it.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu/xenial64"
  config.vm.network "private_network", ip: "192.168.33.99"

  config.vm.synced_folder "/Users/ESL/Sites/project/web__public_web", "/path/where/mounted/on/vm", id: "unique_id_1", type: "rsync", rsync__args: ["--verbose", "--archive", "--delete", "-z"], create: true
  config.vm.synced_folder "/home/vagrant/web__public_web", "/path/where/mounted/on/vm2", id: "unique_id_2", type: "rsync", rsync__args: ["--verbose", "--archive", "--delete", "-z"], create: true

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "2046"
  end

end
Stefan
  • 2,961
  • 1
  • 22
  • 34
0

I answered my own question...

It turns out the sync was working all along. But I misunderstood the directionality of the sync. I was expecting the files in the guest OS to show up in the host directory, but it's the other way around. The empty folder on the host directory was getting synced to the guest and wiping out all the files.

After I manually copied all of the files from the guest to the host directory, the same configurations worked as expected.

Bottom line: if you want to sync an existing guest folder with files in it, you have to manually move it into place on the host OS first.

emersonthis
  • 32,822
  • 59
  • 210
  • 375