Dennis Fischer
Dennis Fischer

Reputation: 81

vagrant box add not recognizing local metadata json file

I am trying to provide my own vagrant basebox in combination with a metadata json file to handle the versioning. However if I try to add the box using to vagrant it fails. Vagrant does not seem to recognize the file as metadata and instead tries to add it as a box, which does not work.

vagrant box add

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."]

Adding the box directly works

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'!

I already checked for the Visual Studio C++ Redistributable 2015 to be installed both in x64 and x86 versions (Vagrant box add fails with local file) and already tried to replace the curl file (Vagrant box add fail)

System: Windows 10 Pro x64
Vagrant Version: 2.0.1

Any help would be appreciated as I do not know why vagrant does not recognize the json file correctly :-/

Upvotes: 4

Views: 6468

Answers (1)

Dennis Fischer
Dennis Fischer

Reputation: 81

After a lot of research if finally found the error.

The problem was the encoding of the metadata.json file. I exported the file using UTF8-BOM which prevented vagrant from recognizing it correctly. After converting to UTF8 or ASCII the box could be added using the metadata file.

Upvotes: 4

Related Questions