我正在尝试提供我自己的 vagrant basebox 与元数据 json 文件相结合来处理版本控制。但是,如果我尝试添加使用 vagrant 的框,它会失败。 Vagrant 似乎没有将该文件识别为元数据,而是尝试将其添加为一个框,但这不起作用。
添加 Vagrant 框
PS C:\Vagrant\Boxes> vagrant box add C:\Vagrant\Bento\builds\metadata.json
==> box: Box file was not detected as metadata. Adding it directly...
A name is required when adding a box file directly. Please pass
the --name parameter to vagrant box add. See
vagrant box add -h for more help.
metadata.json
{
"name": "devops",
"description": "Bla",
"versions": [{
"version": "0.1.0",
"providers": [{
"name": "virtualbox",
"url": "file://C:/Vagrant/Bento/builds/debian-9.3.virtualbox.box"
}]
}]
}
vagrant box add --debug
INFO runner: Preparing hooks for middleware sequence...
INFO runner: 1 hooks defined.
INFO runner: Running action: #<Vagrant::Action::Builder:0x000000000482b258>
INFO warden: Calling IN action: #<Vagrant::Action::Builtin::BoxAdd:0x00000000046d7640>
INFO environment: Running hook: authenticate_box_url
INFO runner: Preparing hooks for middleware sequence...
INFO runner: 2 hooks defined.
INFO runner: Running action: authenticate_box_url #<Vagrant::Action::Builder:0x000000000464dbe8>
INFO warden: Calling IN action: #<VagrantPlugins::LoginCommand::AddAuthentication:0x0000000005444fd0>
DEBUG client: No authentication token in environment or C:/Users/a.b/.vagrant.d/data/vagrant_login_token
INFO warden: Calling OUT action: #<VagrantPlugins::LoginCommand::AddAuthentication:0x0000000005444fd0>
INFO box_add: Downloading box: file:///C:/Vagrant/Bento/builds/metadata.json => C:/Users/a.b/.vagrant.d/tmp/boxed9966a6bed3c379b7650df171216dd6eb5788c8
INFO interface: output: Box file was not detected as metadata. Adding it directly...
INFO interface: output: ==> box: Box file was not detected as metadata. Adding it directly...
==> box: Box file was not detected as metadata. Adding it directly...
ERROR warden: Error occurred: A name is required when adding a box file directly. Please pass
the `--name` parameter to `vagrant box add`. See
`vagrant box add -h` for more help.
INFO warden: Beginning recovery process...
INFO warden: Recovery complete.
INFO environment: Running hook: environment_unload
INFO runner: Preparing hooks for middleware sequence...
INFO runner: 1 hooks defined.
INFO runner: Running action: environment_unload #<Vagrant::Action::Builder:0x00000000056cc0f0>
ERROR vagrant: Vagrant experienced an error! Details:
ERROR vagrant: #<Vagrant::Errors::BoxAddNameRequired: A name is required when adding a box file directly. Please pass
the `--name` parameter to `vagrant box add`. See
`vagrant box add -h` for more help.>
ERROR vagrant: A name is required when adding a box file directly. Please pass
the `--name` parameter to `vagrant box add`. See
`vagrant box add -h` for more help.
ERROR vagrant: C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/action/builtin/box_add.rb:136:in `add_direct'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/action/builtin/box_add.rb:120:in `call'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/action/warden.rb:34:in `call'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/action/builder.rb:116:in `call'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/action/runner.rb:66:in `block in run'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/util/busy.rb:19:in `busy'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/action/runner.rb:66:in `run'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/plugins/commands/box/command/add.rb:78:in `execute'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/plugins/commands/box/command/root.rb:66:in `execute'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/cli.rb:42:in `execute'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/environment.rb:308:in `cli'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/bin/vagrant:138:in `<main>'
INFO interface: error: A name is required when adding a box file directly. Please pass
the `--name` parameter to `vagrant box add`. See
`vagrant box add -h` for more help.
A name is required when adding a box file directly. Please pass
the `--name` parameter to `vagrant box add`. See
`vagrant box add -h` for more help.
INFO interface: Machine: error-exit ["Vagrant::Errors::BoxAddNameRequired", "A name is required when adding a box file directly. Please pass\nthe `--name` parameter to `vagrant box add`. See\n`vagrant box add -h` for more help."]
直接添加盒子即可
PS C:\Vagrant\HoBo> vagrant box add C:\Vagrant\Bento\builds\debian-
9.3.virtualbox.box --name devops
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'devops' (v0) for provider:
box: Unpacking necessary files from: file:///C:/Vagrant/Bento/builds/debian-
9.3.virtualbox.box
box:
==> box: Successfully added box 'devops' (v0) for 'virtualbox'!
我已经检查了 Visual Studio C++ Redistributable 2015 是否安装在 x64 和 x86 版本 ( Vagrant box add fails with local file ) 中,并且已经尝试替换curl 文件 ( Vagrant box add fail )
系统:Windows 10 Pro x64
Vagrant 版本:2.0.1
任何帮助将不胜感激,因为我不知道为什么 vagrant 不能正确识别 json 文件:-/
最佳答案
经过大量研究,终于发现了错误。
问题出在metadata.json 文件的编码上。我使用 UTF8-BOM 导出文件,这导致 vagrant 无法正确识别它。转换为 UTF8 或 ASCII 后,可以使用元数据文件添加该框。
关于json - vagrant box 添加无法识别本地元数据 json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48110467/