Vagrant - 不支持该功能 'change_host_name'

标签 vagrant virtualbox vagrantfile

问题是当我尝试执行以下命令行时, guest 不支持“change_host_name”功能:

vagrant up

它给了我如下错误:
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.

请注意,我的操作系统是:
OS X 优胜美地 10.10.5

guest 添加版本:4.2.0 和 VirtualBox 版本:5.0

我已经尝试了许多其他面临此问题的解决方案,但我无法解决它。

最佳答案

这是https://github.com/mitchellh/vagrant/issues/7625 .它将在下一个版本中修复,在此之前如果它阻止了你,你可以自己修补 vagrant

如果你想给自己打补丁

方法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
  • window :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
    

  • 方法二 : 使用 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
    

    并运行以下命令以应用补丁
    sudo patch -p1 --directory /opt/vagrant/embedded/gems/gems/vagrant-1.8.5/ < vagrant-guest.patch
    

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

    关于Vagrant - 不支持该功能 'change_host_name',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38636023/

    相关文章:

    android - Genymotion 错误 - VirtualBox DHCP 服务器尚未为虚拟设备分配 IP 地址

    ssh - 如何通过主机从外部 SSH 到 VirtualBox guest ?

    vagrant - 执行 Vagrant 用于控制 VirtualBox 的 CLI `VBoxManage` 时出现错误

    ansible - 如何将ansible变量传递给vagrant

    development-environment - 为什么最好使用 Vagrant 而不是共享 VM 的磁盘本身?

    vagrant - 如何添加环境变量。 Vagrant 和 WSL

    Vagrant 错误: symlink has no referent

    vagrant - 如何强制在 Vagrant 机器上运行 playbook?

    java - Java 项目的 Vagrant : should you compile in the VM or on the host?

    mysql - Vagrant & Puppet - 使用 puphpet 将 sql 导入 mysql 数据库时出错