How to show Vagrant box version used in a particular directory
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
.
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"
}
}
$