Check if NFS is available from within Vagrantfile - vagrant

I have a Vagrantfile and the default option for mounting on non windows machines is NFS.
if Vagrant::Util::Platform.windows? == false
config.vm.synced_folder ".", "/vagrant", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
end
However we have a developer that didn't have NFS installed on his 'nix box and it took awhile to figure out that was the problem.
Is there a way to check if the host machine has NFS installed in a similar approach from within the vagrantfile?

You can read this https://www.vagrantup.com/docs/plugins/host-capabilities.html The definition and implementation of host capabilities is identical to guest capabilities.

Related

vagrant private network fails to resolve on windows 10 host

I can't get anything to work. I have windows 10 as my host and my guest VM is centos/7 box. It works great with forwarded_ports but using private_network setting nothing resolves. I'm not sure what to do or check
vagrant file look like
Vagrant.configure("2") do |config|
config.vm.box = "bento/centos-7.4"
config.vm.synced_folder "./website", "/var/www/html/", :mount_options => ["dmode=777", "fmode=777"], owner: "apache", group: "apache"
config.vm.network "private_network", ip: "192.168.50.4"
## Bootstrap script to provision box. All installation methods can go here.
config.vm.provision "shell" do |s|
s.path = "bootstrap.sh"
end
end
My ifconfig on guest looks like
My virtualbox shows two adapters
I get nothing when I browse to the IP on windows
It actually had nothing to do with vagrant. It was all set up correctly, but my magento site had a weird error. Thanks to Frederic for taking the time!

Vagrant - VM can not follow host-symlink within virtualbox synced_folder

I set up a vagrant machine to maintain an older project of mine. I use VirtualBox as provider and created a synced_folder to publish the project to the vm.
The amount of assets is kind of huge (~40GByte), so i dont want to keep that on my ssd. So i moved those assets to an hdd and created a symlink from my project-folder pointing to the hdd. All of this happens on the host system.
My problem is, that when i ssh into my vagrant machine and inspect the assets-folder i can see a broken symlink. I want my vm to follow this path.
The folder structure (the part, that matters) looks like:
root/
|--src/
|--public/
|--|--assets -> /media/hdd
As you can see /root/public/assets points to my hdd mount.
My synced_folder is set up like
Vagrant.configure("2") do |config|
# skipped lines
# skipped lines
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
# skipped lines
# skipped lines
end
Now i dont know how to configure the synced_folder to follow the path on the host machine.
I thought about having another line like
config.vm.synced_folder "/media/hdd", "/vagrant/public/assets", type: "virtualbox"
but i am not the only one using this setup, so i would like to solve it with some kind of option, like:
config.vm.synced_folder ".", "/vagrant", type: "virtualbox", options: ["optionIDontKnowAbout", "1"]
What i tried so far:
config.vm.provider "virtualbox" do |vb|
# should allow symlinks in synced folders
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end
But that did not help.
Thanks in advance
For the moment i use the following workaround. It does not answer my initial quesion, so i wont delete it:
if ENV['USER'].downcase == 'yourusername'
config.vm.synced_folder "/media/hdd", "/media/hdd", type: "virtualbox"
end

Cannot mount vagrant synced folder with nfs

I managed to setting up my Symfony2 project inside a ubuntu vagrant box. But it takes around 20 seconds to load the website through it's webserver. After some research, i came up with using nfs for the sync folder. Here're my setting from Vagrantfile:
config.vm.network "private_network", ip: "192.168.56.101"
config.vm.synced_folder ".", "/vagrant", :nfs => true, :mount_options => ["dmode=777","fmode=777"]
After starting de vagrant box i get the following error
==> default: Mounting NFS shared folders...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o 'dmode=777,fmode=777' 192.168.56.1:'/Users/marcschenk/Projects/teleboy.ch' /vagrant
Stdout from the command:
Stderr from the command:
stdin: is not a tty
mount.nfs: an incorrect mount option was specified
The VM seems to work, but the synced folder's obviously empty. What did i wrong?
My setup:
Vagrant 1.6.5 & Virtualbox 4.3.18
Host: OS X 10.10
Guest: Ubuntu 12.04
Found the solution for the problem here https://github.com/mitchellh/vagrant/issues/2546
The correct syntax for vagrant version 1.3 to 1.6 is:
config.vm.synced_folder ".", "/vagrant", :nfs => { :mount_options => ["dmode=777","fmode=777"] }

config.vm.share_folder setting not found

I am getting this error with this line in my Vagrantfile during vagrant up, until I comment it out.
The setting is documented here:
http://docs-v1.vagrantup.com/v1/docs/config/vm/share_folder.html
Not sure why the following documented paramenter causes an error
config.vm.share_folder "puppetdir", "/etc/puppet", "/vagrant/mypuppetdir"
Bringing machine 'default' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:
vm:
* The following settings don't exist: share_folder
The latest virtualbox and latest vagrant. everything else works fine.
On Vagrant 1.1+ you should use config.vm.synced_folder, the docs you are looking at are for older versions. Please refer to the updated documentation for more info: http://docs.vagrantup.com/v2/synced-folders/basic_usage.html
Shared Folders has been renamed to Synded Folder since 1.1.
In your Vagrantfile you should be using the following
config.vm.synced_folder "../data", "/vagrant_data"
# by default enabled, uncomment to disable
# config.vm.synced_folder ".", "/vagrant", disabled: true
NOTE: By default, Vagrant will share your project directory (the directory where Vagrantfile resides) to /vagrant.
config.vm.synced_folder ".", "/vagrant", disabled: true
More flexible example
vagrant_data = File.expand_path("../vagrant_data", __FILE__)
Dir::mkdir(vagrant_data) unless FileTest::directory?(vagrant_data)
config.vm.synced_folder "vagrant_data", "/vagrant_data"
Take a look at this for more information => shared folders VS synced folders
Extending from https://github.com/mitchellh/vagrant/issues/936#issuecomment-7179034
if you need to mount a volume as a user that doesn't exist when the vm boots you can get there like so:
# Vagrantfile line
config.vm.synced_folder "host_folder", "/svr/fake_mount_folder", id: "whatever_name"
# ...
config.vm.provision "shell", inline: <<-SHELL
# ...
# In my case a package installed a user with UID 110, GID 116
mount -t vboxsf -o uid=110,gid=116 whatever_name /media/actual_mounted_folder
# ...
SHELL

Vagrant failed permissions with nfs only when mounting to apache folders

I am using Linux Mint as Host and CentOS as guest, whenever i am trying to share a folder to an apache folder (example below) it fails and all other apache actions fail to.
config.vm.share_folder "apache", "/var/www/html", "../src", :extra => 'dmode=775,fmode=775', :nfs => (FFI::Platform::IS_WINDOWS ? false: true)
I get following error then:
error: unpacking of archive failed on file /var/www/html: cpio: chown failed - Operation not permitted
However, when i mount the folder to lets say /html, there is not a single problem and my vagrant runs clean.
I am desperatly trying to get things in the folders they are meant to be, any idea how i can fix this?
here we've having some kind of this problem too.
The way it worked here was to adjust the syntax of nfs exporting to:
config.vm.synced_folder ".", "/vagrant", :nfs => { :mount_options => ["dmode=777","fmode=777"] }
as stated in 26710386
note the :nfs line and mount options. You must to use it as
nfs => { :mount_options => ["dmode=777","fmode=777"] }
and not as the latter way type: "nfs", mount_options: ... was.
Hope it helps.

Resources