diff --git a/CHANGELOG.md b/CHANGELOG.md index 84ffee6bc..a5fc6994d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ IMPROVEMENTS: + - hosts/bsd: check NFS exports file for issues prior to exporting - provisioners/docker: Add support for using the provisioner with RedHat based guests [GH-2649] - provisioners/docker: Remove "Docker" prefix from Client and Installer diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 7a41a5e85..ef8a43b9f 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -364,6 +364,10 @@ module Vagrant error_key(:not_found, "vagrant.actions.vm.host_only_network") end + class NFSBadExports < VagrantError + error_key(:nfs_bad_exports) + end + class NFSCantReadExports < VagrantError error_key(:nfs_cant_read_exports) end diff --git a/plugins/hosts/bsd/host.rb b/plugins/hosts/bsd/host.rb index f0214e3c7..c2484a1de 100644 --- a/plugins/hosts/bsd/host.rb +++ b/plugins/hosts/bsd/host.rb @@ -2,6 +2,7 @@ require 'log4r' require "vagrant" require 'vagrant/util/platform' +require "vagrant/util/subprocess" module VagrantPlugins module HostBSD @@ -35,6 +36,8 @@ module VagrantPlugins end def nfs_export(id, ips, folders) + nfs_checkexports! + # We need to build up mapping of directories that are enclosed # within each other because the exports file has to have subdirectories # of an exported directory on the same line. e.g.: @@ -162,6 +165,13 @@ module VagrantPlugins protected + def nfs_checkexports! + r = Subprocess.execute("nfsd", "checkexports") + if r.exit_code != 0 + raise Vagrant::Errors::NFSBadExports, output: r.stderr + end + end + def nfs_cleanup(id) return if !File.exist?("/etc/exports") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 12981a861..f67b5042e 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -429,6 +429,12 @@ en: A multi-vm environment is required for name specification to this command. multi_vm_target_required: |- This command requires a specific VM name to target in a multi-VM environment. + nfs_bad_exports: |- + NFS is reporting that your exports file is invalid. Vagrant does + this check before making any changes to the file. Please correct + the issues below and execute "vagrant reload": + + %{output} nfs_cant_read_exports: |- Vagrant can't read your current NFS exports! The exports file should be readable by any user. This is usually caused by invalid permissions