将盒子添加到流浪汉

时间:2018-04-23 03:35:06

标签: vagrant vagrantfile vagrant-windows

我已经创建了一个用于Hyper-V提供程序的新盒子。当我尝试添加该框时,它会死于以下内容:

PS C:\> vagrant box add sbx-misc-app01 .\img-misc-w2k16.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'sbx-misc-app01' (v0) for provider:
    box: Unpacking necessary files from: file://C:/img-misc-w2k16.box
    box:
C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:156:in `block (3 levels) in add': undefined method `to_sym' for nil:NilClass (NoMethodError)
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:461:in `with_temp_dir'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:134:in `block (2 levels) in add'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:461:in `with_temp_dir'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:115:in `block inadd' from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:448:in `block in with_collection_lock'
        from C:/HashiCorp/Vagrant/embedded/mingw64/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:447:in `with_collection_lock'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:104:in `add'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/builtin/box_add.rb:357:in `box_add'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/builtin/box_add.rb:146:in `add_direct'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/builtin/box_add.rb:120:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/warden.rb:34:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/builder.rb:116:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/runner.rb:66:in `block in run'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/util/busy.rb:19:in `busy'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/runner.rb:66:in `run'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/plugins/commands/box/command/add.rb:78:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/plugins/commands/box/command/root.rb:66:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/cli.rb:46:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/environment.rb:269:in `cli'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/bin/vagrant:151:in `<main>'

问题:

  1. 是否有元数据文件引用?我已经搜查了。我确定它在我面前,但我无法找到它。
  2. 为什么我收到消息&#34;框:未将Box文件检测为元数据。&#34;?我的档案中有一个metadata.json文件。
  3. WTF使用&#34;未定义的方法`to_sym&#39;&#34;错误?
  4. ...环境

    • 虚拟机管理程序操作系统:Microsoft Windows 10企业版(10.0.15063)
    • 来宾操作系统:Windows Server 2016 Standard(64位)
    • 提供商:Hyper-V Vagrant 2.0.3
    • 使用tar在Windows上的Ubuntu上的Bash中创建的文件夹
    • 从Powershell窗口添加

    盒子的内容......

    C:\ img-misc-w2k16 \虚拟硬盘
    C:\ img-misc-w2k16 \虚拟机
    C:\ IMG-MISC-w2k16 \ metadata.json
    C:\ img-misc-w2k16 \虚拟硬盘\ img-misc-w2k16.vhdx
    C:\ img-misc-w2k16 \虚拟机\ AB56D8F5-4F71-4CCD-97E6-237713B79FD8 .... C:\ img-misc-w2k16 \ Virtual Machines \ AB56D8F5-4F71-4CCD-97E6-237713B79FD8 ....

    metadata.json的内容......

    {
        "name": "foo/windowsServer2016x64",
        "description": "This box contains Windows Server 2016 64-bit standard edition.",
        "versions": [
          {
            "version": "1.0.0",
            "providers": [
              {
                "name": "hyperv"
              }
            ]
          }
        ]
      }
    

1 个答案:

答案 0 :(得分:3)

似乎对盒子的不同方面存在一些混淆。

所以从https://www.vagrantup.com/docs/boxes/format.html

开始
  

Box文件 - 这是一个压缩的(tar,tar.gz,zip)文件   特定于单个提供者并且可以包含任何内容。流浪汉核心   不会使用此文件的内容。相反,他们通过了   给提供者。因此,VirtualBox框文件有所不同   来自VMware盒子文件的内容等等。

     

Box Catalog Metadata - 这是一个JSON文档(通常是交换的   在与HashiCorp的Vagrant Cloud交互时,指定了   盒子的名称,描述,可用的版本,可用   提供者,以及每个提供者的实际盒子文件(下一个组件)的URL   提供者和版本。如果此目录元数据不存在,则为一个框   文件仍可以直接添加,但不支持版本控制   和更新。

文件C:\img-misc-w2k16\metadata.json是盒子文件的一部分 - 它与盒子目录元数据(如果你想分发你的盒子时使用)不同,但你共享的内容是盒子目录元数据。

进一步阅读

  

在存档中,Vagrant确实需要一个文件:metadata.json。   这是一个与上面的框完全无关的JSON文件   目录元数据组件; 每个框只有一个metadata.json   文件(在盒子文件中),而一个目录元数据JSON文件   可以描述同一个框的多个版本,可能跨越   多个提供商。

     

metadata.json必须至少包含“provider”键   提供框是为了。 Vagrant使用它来验证提供者   盒子。例如,如果你的盒子是针对VirtualBox的,那么   metadata.json看起来像这样:

     

{ "provider": "virtualbox" }

     

如果没有metadata.json文件或   该文件不包含至少具有“提供者”密钥的有效JSON,   然后Vagrant在添加框时会出错,因为它无法验证   提供者。

所以当你打包你的盒子时,metadata.json的内容应该是

{
  "provider": "hyperv"
}

替换文件内容后,您可以重新打包该框,并且您应该能够从此框中运行VM。

相关问题