0
votes

We have in our projects a Vagrantfile, which is configured to fetch a metadata json as box_url.

In this metadata json, we list all available boxes (different versions and/or providers) as described here

If we execute vagrant up, then vagrant create a virtuelbox with name like <currentfoldername>_default_<timestamp>

I set now a custom virtualboxname as follow:

config.vm.provider "virtualbox" do |vb|
  vb.name = "my-project (centos-67-x64)"
end

But I want the following virtualbox name:

my-project (centos-67-x64) - 1.0.0

The version should come from the version property in metadata.json.

It is possible? I found no information to this topic and i'm wondering, that no other user, has this problem.

1
Have you tried to set vb.name = "my-project (centos-67-x64)" + config.vm.box_versionSebastian Stigler

1 Answers

0
votes

If I understand you well, its about reading json file from ruby.

Taking the example you point, the metadata.json file would be something like

{
  "name": "hashicorp/precise64",
  "description": "This box contains Ubuntu 12.04 LTS 64-bit.",
  "versions": [{
    "version": "0.1.0",
    "providers": [{
      "name": "virtualbox",
      "url": "http://somewhere.com/precise64_010_virtualbox.box",
      "checksum_type": "sha1",
      "checksum": "foo"
    }]
  }]
}

and so you want the version information. Then the Vagrantfile would be something like

require 'json'

file = File.read('metadata.json')
data_hash = JSON.parse(file)
version = data_hash['versions'][0]['version']

Vagrant.configure(2) do |config|

  <blablabla>

  config.vm.provider "virtualbox" do |vb|
    vb.name = "my-project (centos-67-x64) - " + version
  end
end