ponkiti's blog

主に自分用、イベント参加メモや備忘録として利用

VagrantでPluginを使う

さらにこの記事の続き。

Pluginをインストールする

$ vagrant plugin install plugin_name

Pluginのインストールに失敗したケースへの対応

Sandboxモードを有効にしてくれるSaharaというプラグインを入れてみる。仮想マシンへの変更を戻すことができるらしい。

$ vagrant plugin install sahara
Installing the 'sahara' plugin. This can take a few minutes...
Building nokogiri using packaged libraries.
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:

An error occurred while installing nokogiri (1.6.3.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.3.1'` succeeds before bundling.

「Nokogiriをインストールせよ」という主旨のメッセージが出て、Saharaのインストールに失敗した。いくつかのサイトを見てみると、XcodeCommand Line Toolsのインストールが必要とのこと。環境はMacOS 10.9.5。これもMavericksへのアップグレードが原因か??

$ xcode-select --install
xcode-select: note: install requested for command line developer tools

f:id:pyoonn:20140930143717p:plain

コマンドライン・ディベロッパ・ツールをインストールし、Saharaのインストールに再チャレンジ。

$ vagrant plugin install sahara
(省略)
Installed the plugin 'sahara (0.0.17)’!

Vagrantにインストール済みのリストを表示し、Saharaがインストールされたことを確認する。

$ vagrant plugin list
sahara (0.0.17)
vagrant-login (1.0.1, system)
vagrant-share (1.1.1, system)

Pluginをアンインストールする

$ vagrant uninstall plugin_name

Saharaを利用する

Sandboxモードを実行する

$ vagrant sandbox on
[default] Starting sandbox mode...
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Sandboxのステータスを確認する

$ vagrant sandbox status
[default] Sandbox mode is on

仮想マシン上でファイルを作成後、ファイル作成自体をロールバックすると、作成前の状態に戻っているのが分かる。

$ vagrant ssh
(省略)
[vagrant@localhost ~]$ touch test
[vagrant@localhost ~]$ ls
test
[vagrant@localhost ~]$ exit
logout
Connection to 127.0.0.1 closed.
$ vagrant sandbox rollback
[default] Rolling back the virtual machine...
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

$ vagrant ssh
(省略)
[vagrant@localhost ~]$ ls

vagrant suspendして、仮想マシンを保留状態にする。

$ vagrant suspend
==> default: Saving VM state and suspending execution...

変更をコミットする。

$ vagrant sandbox commit
[default] Committing the virtual machine...
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%…100%

$ vagrant sandbox off
[default] Stopping sandbox mode...
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

$ vagrant sandbox status
[default] Sandbox mode is off

参照