Vagrant - 不支持"change_host_name"功能

dsd*_*sds 17 virtualbox vagrant vagrantfile

问题是当我尝试执行以下命令行时,guest虚拟机不支持"change_host_name"功能:

vagrant up
Run Code Online (Sandbox Code Playgroud)

它给我一个错误如下:

Vagrant attempted to execute the capability 'change_host_name'
on the detect guest OS 'linux', but the guest doesn't
support that capability. This capability is required for your
configuration of Vagrant. Please either reconfigure Vagrant to
avoid this capability or fix the issue by creating the capability.
Run Code Online (Sandbox Code Playgroud)

请注意,我的操作系统是:OS X Yosemite 10.10.5

Guest Additions版本:4.2.0和VirtualBox版本:5.0

我已经尝试过许多面对这个问题的人的解决方案,但我无法修复它.

Fré*_*nri 26

这是https://github.com/mitchellh/vagrant/issues/7625.它将在下一个版本中修复,直到那时如果它阻止你,你可以自己修补流浪汉

如果你想修补自己

方法1:

  • plugins/guests/ubuntu/guest.rb在你的vagrant安装中搜索文件
    • 例如/opt/vagrant/embedded/gems/gems/vagrant-1.8.5/plugins/guests/ubuntu/guest.rb在mac/linux上默认安装
    • 要么 /opt/vagrant/embedded/gems/vagrant-1.8.5/plugins/guests/ubuntu/guest.rb
    • 窗户: C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.5\plugin??s\guests\ubuntu\gues??t.rb
  • 替换为 https://raw.githubusercontent.com/carlosefr/vagrant/1c631c18d1a654405f6954459a42ac19a1a2f096/plugins/guests/ubuntu/guest.rb(如果您以管理员身份安装,请确保拥有正确的权限,您必须是管理员用户才能保存文件)
  • 或者编辑文件并替换所有内容

    module VagrantPlugins
      module GuestUbuntu
        class Guest < Vagrant.plugin("2", :guest)
          def detect?(machine)
            # This command detects if we are running on Ubuntu. /etc/os-release is
            # available on modern Ubuntu versions, but does not exist on 14.04 and
            # previous versions, so we fall back to lsb_release.
            #
            #   GH-7524
            #   GH-7625
            #
            machine.communicate.test <<-EOH.gsub(/^ {10}/, "")
              if test -r /etc/os-release; then
                source /etc/os-release && test xubuntu = x$ID
              elif test -x /usr/bin/lsb_release; then
                /usr/bin/lsb_release -i 2>/dev/null | grep -q Ubuntu
              else
                exit 1
              fi
            EOH
          end
        end
      end
    end
    
    Run Code Online (Sandbox Code Playgroud)

方法2:使用patch命令修补文件的替代方法:

保存下面的文件 vagrant-guest.patch

commit 00fa49191dba2bb7c6322fa8df9327ca505c0b41
Author: Seth Vargo <sethvargo@gmail.com>
Date:   Sat Jul 23 11:40:36 2016 -0400

    guests/ubuntu: Revert detection

    - Semi-reverts GH-7524
    - Fixes GH-7625

diff --git a/plugins/guests/ubuntu/guest.rb b/plugins/guests/ubuntu/guest.rb
index 9aeb7aa..f60108e 100644
--- a/plugins/guests/ubuntu/guest.rb
+++ b/plugins/guests/ubuntu/guest.rb
@@ -2,7 +2,22 @@ module VagrantPlugins
   module GuestUbuntu
     class Guest < Vagrant.plugin("2", :guest)
       def detect?(machine)
-        machine.communicate.test("test -r /etc/os-release && . /etc/os-release && test xubuntu = x$ID")
+        # This command detects if we are running on Ubuntu. /etc/os-release is
+        # available on modern Ubuntu versions, but does not exist on 14.04 and
+        # previous versions, so we fall back to lsb_release.
+        #
+        #   GH-7524
+        #   GH-7625
+        #
+        machine.communicate.test <<-EOH.gsub(/^ {10}/, "")
+          if test -r /etc/os-release; then
+            source /etc/os-release && test xubuntu = x$ID
+          elif test -x /usr/bin/lsb_release; then
+            /usr/bin/lsb_release -i 2>/dev/null | grep -q Ubuntu
+          else
+            exit 1
+          fi
+        EOH
       end
     end
   end
Run Code Online (Sandbox Code Playgroud)

并运行以下命令以应用修补程序

sudo patch -p1 --directory /opt/vagrant/embedded/gems/gems/vagrant-1.8.5/ < vagrant-guest.patch
Run Code Online (Sandbox Code Playgroud)

只需替换/opt/vagrant/embedded/gems/gems/vagrant-1.8.5(或/opt/vagrant/embedded/gems/vagrant-1.8.5/plugins/guests/ubuntu/guest.rb)您的vagrant文​​件夹安装