LoginSignup
19
12

More than 5 years have passed since last update.

Vagrantの亡霊マシンを成仏させる

Posted at

この記事のサマリ

vagrant global-statusを実行したら、もう物理ディレクトリを削除してしまったマシンが残っていて気持ち悪い。。。そんなときは、vagrant global-status --pruneを実行して成仏させましょうというお話です。

対象読者

vagrantを利用している方で、vagrant global-statusを実行したら、「コイツ何者!!」とか、マシンを作成したディレクトリは削除してしまったからdestroyできない。。。って感じでお困りの方。

動作確認バージョン

vagrant versionの結果↓
Installed Version: 1.7.4

経緯

vagrantのコマンドと戯れていて、おもむろにvagrant global-statusを実行してみたら、すでに物理削除したマシンが亡霊のように残っていました。。。恐怖にかられた私は、除霊しようと思いvagrant destroy [マシンのID]というコマンドで除霊を試みました。。。
しかし!!作業用ディレクトリがもうないから消せないんだぜ!!って言われて成仏してくれませんでした。じゃぁどうすればいいのよ!!ってなって調べてみました。

除霊に至るまでの詳細

いろいろな実験用のsandbox環境をvagrantで作ってきたから、何があるのかよくわかんなくなってきたから、今の状況を一覧化したいなぁ。。。
おっ、vagrant global-statusを打つと、分かるらしい。。。
→やってみよう!!

$ vagrant global-status
id       name           provider   state    directory
------------------------------------------------------------------------------------------------
0464ba6  for_rails      virtualbox running  C:/cygwin64/home/yukimura1227/vagrant_example2
bb8f69c  for_mean       virtualbox running  C:/cygwin64/home/yukimura1227/vagrant_mean
91fbaa3  for_mysql      virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_mysql
239a0b1  for_docker     virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_coreos_jikken
bd80dd1  core-01        virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_coreos4docker
cf94378  cent7_0        virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_cent7
6a0222a  my_develop_env virtualbox running  C:/cygwin64/home/yukimura1227/vagrant_my_dev_env

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"

あれぇ。。for_meanは、フォルダ毎削除してしまったマシンだなぁ。ふむふむ、idを指定してvagrant destoryしてあげれば、消えてくれるのかな??
→やってみよう!!

$ vagrant destroy bb8f69c
The working directory for Vagrant doesn't exist! This is the
specified working directory:

C:/cygwin64/home/yukimura1227/vagrant_mean

$ vagrant global-status
id       name           provider   state    directory
------------------------------------------------------------------------------------------------
0464ba6  for_rails      virtualbox running  C:/cygwin64/home/yukimura1227/vagrant_example2
bb8f69c  for_mean       virtualbox running  C:/cygwin64/home/yukimura1227/vagrant_mean
91fbaa3  for_mysql      virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_mysql
239a0b1  for_docker     virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_coreos_jikken
bd80dd1  core-01        virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_coreos4docker
cf94378  cent7_0        virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_cent7
6a0222a  my_develop_env virtualbox running  C:/cygwin64/home/yukimura1227/vagrant_my_dev_env

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"

成仏しない!!ヤッベェゾ!!
https://www.vagrantup.com/docs/cli/global-status.html
に記載がありました。
global-statusのオプションに--pruneがあるので、それを利用するとよいようです。
pruneというのは、「不要なものを取り除く」という意味ですね。
→やってみよう!!!

yukimura1227@yukimura_x250 ~
$ vagrant global-status --prune
id       name           provider   state    directory
------------------------------------------------------------------------------------------------
0464ba6  for_rails      virtualbox running  C:/cygwin64/home/yukimura1227/vagrant_example2
91fbaa3  for_mysql      virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_mysql
239a0b1  for_docker     virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_coreos_jikken
bd80dd1  core-01        virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_coreos4docker
cf94378  cent7_0        virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_cent7
6a0222a  my_develop_env virtualbox running  C:/cygwin64/home/yukimura1227/vagrant_my_dev_env

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"

yukimura1227@yukimura_x250 ~
$ vagrant global-status
id       name           provider   state    directory
------------------------------------------------------------------------------------------------
0464ba6  for_rails      virtualbox aborted  C:/cygwin64/home/yukimura1227/vagrant_example2
91fbaa3  for_mysql      virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_mysql
239a0b1  for_docker     virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_coreos_jikken
bd80dd1  core-01        virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_coreos4docker
cf94378  cent7_0        virtualbox poweroff C:/cygwin64/home/yukimura1227/vagrant_cent7
6a0222a  my_develop_env virtualbox running  C:/cygwin64/home/yukimura1227/vagrant_my_dev_env

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"

おぉ!!for_meanが成仏してくれた!!
一度、--pruneオプションをつけて実行すると、クリーニングされて次からはオプションつけなくても出てこなくなるみたいですね。

簡単に亡霊マシンが成仏してくれてよかったです。

19
12
1

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
19
12