diff --git a/CHANGELOG.md b/CHANGELOG.md index 0662d438a..9043b5320 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ IMPROVEMENTS: plugins. - commands/plugin: `vagrant plugin install` can now install multiple plugins. + - synced\_folders/nfs: If the guest supports it, NFS clients will be + automatically installed in the guest. BUG FIXES: diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 25b1e8444..1c5dc7c37 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -360,6 +360,10 @@ module Vagrant error_key(:nfs_no_valid_ids) end + class NFSClientNotInstalledInGuest < VagrantError + error_key(:nfs_client_not_installed_in_guest) + end + class NoDefaultSyncedFolderImpl < VagrantError error_key(:no_default_synced_folder_impl) end diff --git a/plugins/guests/debian/cap/nfs_client.rb b/plugins/guests/debian/cap/nfs_client.rb new file mode 100644 index 000000000..8a15ec5b5 --- /dev/null +++ b/plugins/guests/debian/cap/nfs_client.rb @@ -0,0 +1,14 @@ +module VagrantPlugins + module GuestDebian + module Cap + class NFSClient + def self.nfs_client_install(machine) + machine.communicate.tap do |comm| + comm.sudo("apt-get -y update") + comm.sudo("apt-get -y install nfs-common portmap") + end + end + end + end + end +end diff --git a/plugins/guests/debian/plugin.rb b/plugins/guests/debian/plugin.rb index 45fc1544a..88f27a4e8 100644 --- a/plugins/guests/debian/plugin.rb +++ b/plugins/guests/debian/plugin.rb @@ -20,6 +20,11 @@ module VagrantPlugins require_relative "cap/change_host_name" Cap::ChangeHostName end + + guest_capability("linux", "nfs_client_install") do + require_relative "cap/nfs_client" + Cap::NFSClient + end end end end diff --git a/plugins/guests/linux/cap/nfs_client.rb b/plugins/guests/linux/cap/nfs_client.rb new file mode 100644 index 000000000..8e51da37c --- /dev/null +++ b/plugins/guests/linux/cap/nfs_client.rb @@ -0,0 +1,11 @@ +module VagrantPlugins + module GuestLinux + module Cap + class NFSClient + def self.nfs_client_installed(machine) + machine.communicate.test("test -x /sbin/mount.nfs") + end + end + end + end +end diff --git a/plugins/guests/linux/plugin.rb b/plugins/guests/linux/plugin.rb index c47a9d674..42abed371 100644 --- a/plugins/guests/linux/plugin.rb +++ b/plugins/guests/linux/plugin.rb @@ -36,6 +36,11 @@ module VagrantPlugins Cap::MountVirtualBoxSharedFolder end + guest_capability("linux", "nfs_client_installed") do + require_relative "cap/nfs_client" + Cap::NFSClient + end + guest_capability("linux", "read_ip_address") do require_relative "cap/read_ip_address" Cap::ReadIPAddress diff --git a/plugins/guests/redhat/cap/nfs_client.rb b/plugins/guests/redhat/cap/nfs_client.rb new file mode 100644 index 000000000..51d5a8359 --- /dev/null +++ b/plugins/guests/redhat/cap/nfs_client.rb @@ -0,0 +1,13 @@ +module VagrantPlugins + module GuestRedHat + module Cap + class NFSClient + def self.nfs_client_install(machine) + machine.communicate.tap do |comm| + comm.sudo("yum -y install nfs-utils nfs-utils-lib") + end + end + end + end + end +end diff --git a/plugins/guests/redhat/plugin.rb b/plugins/guests/redhat/plugin.rb index 60ca17af6..8024721e5 100644 --- a/plugins/guests/redhat/plugin.rb +++ b/plugins/guests/redhat/plugin.rb @@ -25,6 +25,11 @@ module VagrantPlugins require_relative "cap/network_scripts_dir" Cap::NetworkScriptsDir end + + guest_capability("linux", "nfs_client_install") do + require_relative "cap/nfs_client" + Cap::NFSClient + end end end end diff --git a/plugins/synced_folders/nfs/synced_folder.rb b/plugins/synced_folders/nfs/synced_folder.rb index c2b43cf37..1eabc5d82 100644 --- a/plugins/synced_folders/nfs/synced_folder.rb +++ b/plugins/synced_folders/nfs/synced_folder.rb @@ -37,6 +37,16 @@ module VagrantPlugins raise Vagrant::Errors::NFSNoHostIP if !nfsopts[:nfs_host_ip] raise Vagrant::Errors::NFSNoGuestIP if !nfsopts[:nfs_machine_ip] + if machine.guest.capability?(:nfs_client_installed) + installed = machine.guest.capability(:nfs_client_installed) + if !installed + can_install = machine.guest.capability?(:nfs_client_install) + raise Vagrant::Errors::NFSClientNotInstalledInGuest if !can_install + machine.ui.info I18n.t("vagrant.actions.vm.nfs.installing") + machine.guest.capability(:nfs_client_install) + end + end + machine_ip = nfsopts[:nfs_machine_ip] machine_ip = [machine_ip] if !machine_ip.is_a?(Array) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 8ba185c44..a7bdb542c 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -469,6 +469,14 @@ en: No valid IDs were given to the NFS synced folder implementation to prune. This is an internal bug with Vagrant and an issue should be filed. + nfs_client_not_installed_in_guest: |- + No NFS client was detected as installed in your guest machine. This + is required for NFS synced folders to work. In addition to this, Vagrant + doesn't know how to automatically install NFS for your machine, so + you must do this manually. + + If this message is erroneous, you may disable this check by setting + `config.nfs.verify_installed` to `false` in your Vagrantfile. no_default_synced_folder_impl: |- No synced folder implementation is available for your synced folders! Please consult the documentation to learn why this may be the case. @@ -1116,6 +1124,7 @@ en: preparing: "Preparing host only network..." nfs: exporting: Exporting NFS shared folders... + installing: "Installing NFS client..." mounting: Mounting NFS shared folders... provision: beginning: "Running provisioner: %{provisioner}..."