vagrant - Vagrantfile: sync multiple folders - vagrant

I have tried the following to sync multiple folders from host to guest machine.
But only one folder is getting synced, the later one.
config.vm.synced_folder "host/site1", "/var/www/site1"
config.vm.synced_folder "host/site2", "/var/www/site2"

In newest virtualbox and vagrant versions this is improved and work without problems...

Related

How to put files into Vagrant?

I did an internship and they used vagrant so all the developers whould run the same latest version of the web application.
But now i want to create my own vagrant webserver.
I got to the point that i setup vagrant using the hashicorp/precise32 box.
I got nginx running on my own special ip adress that i changed in the hosts file.
So now i can go to mytestsite.com and it will show me welcome to nginx.
But now my question is, how can i get my own file(small test web application) into the vagrant server because i do not know how to transfer my files to vagrant.
And how can i let my friends use my vagrant test web application.
Thank you for your help!
Sincerely Mex
19 years old
web application student in the Netherlands
By default vagrant will have a synced folder between your vm and the host machine. It is in the same folder as the vagrantfile and can accessed through /vagrant on your host machine.
However if you want more customization and mount certain folders on your host machine and sync them to the vagrant VM it can be done in the vagrant file as follows:
Vagrant.configure("2") do |config|
# other config here
config.vm.synced_folder "src/", "/srv/website"
end
Here is a quick guide to get you started using vagrants synced folders and the example i posted

Default shared folder in vagrant not visible

I have a problem with synced folder in Vagrant. My config is really simple:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.synced_folder ".", "/vagrant"
end
Vagrant usually creates /vagrant folder automatically on start - this time it did not happen so I've done it manually.
But when I create a file in my host system - it's not visible in guest. Any ideas why?
I've succesfully created a similar configuration with:
config.vm.box = "hashicorp/precise64"
but it's a little bit outdated and I want to use Ubuntu 16.04.
Is it a problem with my config, vagrant box, or something else?
You could try: Make sure you have the latest version of Vagrant and VB. Restart your computer (I know, but it sometimes does help in these cases). Try again in a new directory (or vagrant destroy if you want to start fresh and don't need any old content), i.e., make sure the old .vagrant directory isn't there.
vagrant up or vagrant reload and check again.
Assuming you are using VirtualBox, make sure you don't have any "Guest Additions" issues. You could try https://github.com/dotless-de/vagrant-vbguest
If it still doesn't work, check the --debug output again as #frédéric-henri mentioned -- look for all mentions of your share name. Also "/vagrant" isn't always the default, it depends on the box. Sometimes it's "/vagrant_data" or others, but if you specify "/vagrant" in the config -- that should work.

vagrant windows folder setup

I'm setting up vagrant on my Windows 7 and configuring Vagrantfile. Can I set the actual folder and guest folder to be the same? Here is my code:
config.vm.synced_folder "C:\Users\dmitry\VM\code", "/vagrant/code"
Yes you can. I used the config like below and it worked beautifully:
config.vm.synced_folder "C:/git/ui", "/home/vagrant/ui"

Vagrantfile: Disabling synced folders for one provider, but not another

I have been using Vagrant with VirtualBox for local development. Now, I want to deploy to Azure (question would be same with AWS).
When working locally with VirtualBox, it's awesome to have the synced folder. But I definitely don't want a synced folder for the cloud VM. So, how can I have it enabled for the former but disabled for the latter?
A snippet of my vagrantfile is below; however this doesn't seem to have any effect. Appreciate any pointers.
Vagrant.configure('2') do |config|
config.vm.synced_folder ".", "/vagrant"
# …
config.vm.provider :azure do |azure, override|
override.vm.synced_folder ".", "/vagrant", disabled: true
# …
End
# …
end
I've also tried initially disabling the synced folder, and then enabling it only for VirtualBox - but Azure still prompts for username/password and attempts to create an SMB share.
Update: Even if I disable it in the main section, and don't touch it for Azure, it still tries to create a SMB share, and complains that it can't find my machine (my laptop is behind NAT).
It turns out that the default synced folder was indeed being disabled correctly.
However, the Chef provisioner was being used, and behind the scenes this also uses synced folders! The solution therefore is to use a Chef server, or as I chose - to do everything via a shell provisioner.
Hope this question helps someone encountering this problem in the future.
I had the same problem with SMB synced folders not staying disabled even though I hade the correct lines to disable.
My problem was also caused by chef enabling synced folders again. I solved my problem by adding the chef.synced_folder_type = "rsync" to the chef config block:
config.vm.provision :chef_solo do |chef|
chef.synced_folder_type = "rsync"
[...more chef config...]
end

Why is Vagrant hosting my project directory on the guest machine?

For a project with a file /foo/bar/Vagrantfile, Vagrant shares/syncs /foo/bar on the host machine as /vagrant on the guest machine.
Why is it doing this? It appears to be undesirable: the whole point is achieving isolation, but this sharing destroys isolation: a buggy VM can delete my project directory, and my tinkering with my project can affect the VM.
So, what is the point of this? Is it necessary for something I've overlooked?
Vagrant by default sync the project directory (where Vagrantfile resides) with /vagrant within the guest.
If it is NOT desired, it can be disabled by explicitly disable the synced folder config in Vagrantfile and then a vagrant reload is needed.
config.vm.synced_folder ".", "/vagrant", disabled: true
If one-off or manual sync is required, use the new rsync type added in vagrant 1.5.x.

Resources