Vagrant synced_folder id option - vagrant

The syntax for enabling an NFS folder share in Vagrant is commonly posted as:
config.vm.synced_folder "<HOST_DIR>", "<VM_DIR>", id: "???", type: "nfs", mount_options: ["nolock", "vers=3", "udp"]
Note the id argument. I've read the Vagrant docs at https://docs.vagrantup.com/v2/synced-folders/basic_usage.html, but this option isn't mentioned.
Given its frequent use in Vagrantfiles, I assume this option is relevant, if not mandatory. What exactly does it do?

When using the default VirtualBox shared folder mechanism, the id option will be what appears when you list your mount points in the guest OS using mount. For example:
Vagrantfile
config.vm.synced_folder "<HOST_DIR>", "/opt/bar", id: "foo"
Guest OS via SSH
$ mount
...
foo on /opt/bar type vboxsf (uid=1000,gid=1000,rw)
I have not tested whether the id option is used for nfs synced folders, but I can confirm that it has no bearing on rsync synced folders.

Related

Is "vagrant up" possible from different local directories with custom URLs?

I have two directories under /var/www/html, named vlp1 and vlp2 with Vagrant setup. If I run vagrant up separately in these folders the default local URL is vagrant.local for both. But vagrant.local/ always loads site from vlp1 folder.
As it should be, vagrant global-status shows that I have two virtual machines running under these directories. I require to run both sites side by side and to do this the only option I see is to have separate URLs. I believe there is a way to assign different URLs to different sites but don't have any idea how!
What I need to do to accomplish the above so that my sites run like local.vlp1.com and local.vlp2.com or may be like vagrant.vlp1 and vagrant.vlp2?
According to project instructions I have to keep two sites completely separated in two folders and have to use separate Vagrantfiles.
OS: Ubuntu 14.04 64 bit
Installed VitualBox version: 5.1
Installed Vagrant version: 1:1.9.4
Thank you!
UPDATE
Went through the following steps as advised by Henri:
Step 1:
$ vagrant global-status
Output:
id name provider state directory
------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox running /var/www/html/vlp2
Step 2: Did a graceful shutdown on vlp2
$ vagrant halt 190608c
Step 3: Output of vagrant global-status now is
id name provider state directory
-------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox poweroff /var/www/html/vlp2
Step 4:
$ sudo gedit /var/www/html/vlp2/Vagrantfile
if CONF['ip'] == "dhcp"
config.vm.network :private_network, type: "dhcp", hostsupdater: "skip"
else
config.vm.network :private_network, ip: "192.168.2.5"
end
Step 5: Re up'd vlp2 machine
$ vagrant up 190608c
Step 6:
$ vagrant global-status now shows both machine are back to running state again.
id name provider state directory
------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox running /var/www/html/vlp2
Step 7:
In /etc/hosts added following entry
192.168.2.5 vagrant.vlp2
Finally I tried vagrant.vlp2/ in browser but ended up with the following message:
This site can’t be reached
http://vagrant.vlp2/ is unreachable.
As I understand you're using multiple VM so the easiest in this case is to assign each of the VM a static IP (that must be different) so you do so in Vagrantfile
Vagrant.configure("2") do |config|
...
config.vm.network "private_network", ip: "192.168.10.x"
...
end
and you use another IP for the second VM
Vagrant.configure("2") do |config|
...
config.vm.network "private_network", ip: "192.168.20.y"
...
end
and then you update your /etc/hosts file with the information
192.168.10.x vagrant.vlp1
192.168.20.y vagrant.vlp2

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.

Use nfs to for default folder with vagrant

I want to migrate a big project (5000 files) to vagrant with virtualbox.
Virtualbox shared folders is known to be slow for big project, so I want to use NFS.
But, I don't find the right way to use NFS instead of the default shared folder issue. It works when I put code in another folder, and share it. But I want to integrate Vagrant in the current one.
config.vm.synced_folder '.', '/vagrant', nfs: true
doesn't work:
exportfs: duplicated export entries:
exportfs: 10.11.12.13:/home/vincent/workspace/gp
exportfs: 10.11.12.13:/home/vincent/workspace/gp
Any idea to solve this strange issue?
Thank you.
Update 1
Same error with these parameters
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.synced_folder ".", "/home/vagrant/gp", nfs: true
Here is the full error stack:
nfsd running
exportfs: duplicated export entries:
exportfs: 10.11.12.13:/home/vincent/workspace/gp
exportfs: 10.11.12.13:/home/vincent/workspace/gp
==> default: Mounting NFS shared folders...
Vagrant::Errors::LinuxNFSMountFailed: The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o 'vers=3,udp' 10.11.12.1:'/home/vincent/workspace/gp' /home/vagrant/gp
Stdout from the command:
Stderr from the command:
stdin: is not a tty
mount.nfs: access denied by server while mounting 10.11.12.1:/home/vincent/workspace/gp
You may need to explicitly disable the default synced folder by adding the following line in your Vagrantfile so as to mount the NFS share to /vagrant
config.vm.synced_folder ".", "/vagrant", disabled: true
After than do a vagrant reload and see if it works.
In addition, consider using rsync type synced folder for your use case, I think it works even better. See https://docs.vagrantup.com/v2/synced-folders/rsync.html
You can also get this error message if you are trying to create a vm in a directory above another previously created vm. You will need to destroy the the vm's in each sub-directory.

How to disable shared folders for puppet provisioner in Vagrant

I want to disable creating and mounting any shared folders for vagrant VMs.
I've found a way to disable sharing main /vagrant folder and instead uploading necessary files, but not able to find a way to disable shared folder creation for puppet provisioner.
I want to upload puppet files to VM instead of sharing from my host OS. Is it possible to do?
You could use rsync synced folder type (the docs):
Vagrant.configure("2") do |config|
config.vm.provision "puppet" do
puppet.synced_folder_type = "rsync"
# ...
end
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