Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show Vagrant box version used in a particular directory

Tags:

vagrant

I have multiple Vagrant boxes, and would like to see what version of what box is running in which directory.
vagrant box list returns a global list of boxes:

puphpet/centos65-x64   (virtualbox, 1.2.1)
puphpet/centos65-x64   (virtualbox, 2.0)

vagrant global-status shows directories with providers:

id       name    provider   state    directory
--------------------------------------------------
a427238  default virtualbox poweroff /path/to/dir1
fa21751  default virtualbox running  /path/to/dir2

But how can I see which Vagrant box version is used in which directory?

like image 491
Mark Avatar asked Jul 29 '15 22:07

Mark


People also ask

How do I find my vagrant box version?

Command: vagrant version If you only want to see the currently installed version, use vagrant --version .

How do I check my vagrant status?

Command: vagrant status [name|id] This will tell you the state of the machines Vagrant is managing. It is quite easy, especially once you get comfortable with Vagrant, to forget whether your Vagrant machine is running, suspended, not created, etc. This command tells you the state of the underlying guest machine.

Where are vagrant boxes stored Linux?

As mentioned in the docs, boxes are stored at: Mac OS X and Linux: ~/. vagrant. d/boxes.


2 Answers

This data is possible to retrieve but is not exposed, as far as I know, through the Vagrant CLI. Take a look in ~/.vagrant.d/data/machine-index/index for Linux or macOS and I would assume it'd be something like C:\Users\whoever\.vagrant.d\data\machine-index on Windows.

You'll get some unformatted JSON which contains details on every machine Vagrant knows about. If you run the JSON through a pretty-printer/beautifier you'll get one of these for every machine:

"d62342a255436211725abe8fd3c313ea": {
    "local_data_path": "/Users/whoever/mymachine/.vagrant",
    "name": "default",
    "provider": "virtualbox",
    "state": "poweroff",
    "vagrantfile_name": null,
    "vagrantfile_path": "/Users/whoever/mymachine",
    "updated_at": null,
    "extra_data": {
        "box": {
            "name": "ubuntu/xenial64",
            "provider": "virtualbox",
            "version": "20170706.0.0"
        }
    }
},

And the box information associated with your machine is right there. The ubuntu/xenial64 box on the virtualbox provider version 20170706.0.0.

like image 132
Kevin Mark Avatar answered Sep 20 '22 18:09

Kevin Mark


This is kind of an old thread, but I ran into this situation recently that matched the original request, and I discovered an answer that is not listed here:

The vagrant box outdated command lists the current box version number when it tests to see if there is a newer version of the box.

The caveat is that the vagrant box outdated command needs access to the internet to check the current version, which it also outputs.

I only discovered this after I had written this bash script that uses jq to search for the current directory in the ~/.vagrant.d/data/machine-index/index file. I make no guarantees that this will work in your environment:

$ cat ~/scripts/vagrant_box_info.sh
#!/bin/bash

CUR_DIR=`pwd`

JQ_CMD='.machines|to_entries|map(select(.value.vagrantfile_path|test("'$CUR_DIR'$")))[].value.extra_data'

cat ~/.vagrant.d/data/machine-index/index | jq "$JQ_CMD"

$ ~/scripts/vagrant_box_info.sh
{
  "box": {
    "name": "geerlingguy/centos7",
    "provider": "virtualbox",
    "version": "1.2.15"
  }
}
$
like image 26
John Helmuth Avatar answered Sep 16 '22 18:09

John Helmuth