LoginSignup
4
2

More than 5 years have passed since last update.

Vagrantのglobal-statusを高速かつBoxのバージョンも確認できるようにする

Posted at

Vagrantで複数環境を管理するとvagrant global-statusを多用するのですが、遅くていらいらさせられるのと、Boxの名前やバージョンが分からないので、jqqで代替品を作成しました。Windows用ですが、他の環境でも参考になると思います。

下記の内容で vagrant-global-status.bat を作成します。

vagrant-global-status.bat
@ECHO OFF
jq -r ".machines | to_entries[] | \"\(.key[0:7]) \(.value.name) \(.value.provider) \(.value.state) \(.value.vagrantfile_path) \(.value.extra_data.box.name) \(.value.extra_data.box.version)\"" < %USERPROFILE%\.vagrant.d\data\machine-index\index | q -b -E cp932 "SELECT * FROM - ORDER BY c5"

実行例

vagrant global-statusとvagrant-global-status.batの実行結果の比較です。vagrant-global-statusはboxの名前とバージョンが確認できます。

C:\home>vagrant global-status
id       name    provider   state    directory
-------------------------------------------------------------------------
de09131  default virtualbox poweroff C:/home/docker
123ecfb  default virtualbox running  C:/home/vagrant-oracle12.1

The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"

C:\home>vagrant-global-status
de09131 default virtualbox poweroff C:/home/docker             boxcutter/ubuntu1604 2.0.21
123ecfb default virtualbox running  C:/home/vagrant-oracle12.1 boxcutter/ol72       3.0.7

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2