Quantcast
Channel: 蒼の王座・裏口 » vagrant実践
Viewing all articles
Browse latest Browse all 2

実践Vagrantの7章:一部サンプルが動作しない件の対処方法

$
0
0

「Vagrant実践」を読んで、サンプルを作成すると多少(自分的にはかなり)はまる。
調べてみると、「"実践Vagrant"を読んだ」の投稿をしている人もはまっていた。

すこしハマった部分.本書や公式ドキュメントだとVagrantfileVagrant.require_plugin "my_plugin"を記述してプラグインのテストを行うように書かれているが,自分の環境だとうまく動かなかった.

これで、どうやら自分のローカル環境依存じゃないとわかって、よーやくブレークスルーできた。
それで調べ直したら、解決方法がわかったのでメモておく。

エラー内容

サンプルでは、Vagrantfileに以下記述をすることで、bundlerでプラグインを強制的に読み込ませるっと案内があります。

Vagrant.require_plugin ‘my_vagrant_plugin’

書籍の手順に従うと、Vagrant 1.5.0.dev版を使うことになるのだけど、このバージョンでは仕様変更が入っていて動作しない。まぁ次のようなエラーがでる。

Vagrant.require_plugin is deprecated and has no effect any longer.

あかんねー。

解決策

ここで説明されていて、用はrequire_pluginを使う方法からグループを使う方法に変更されたと。
なので、Vagrant実践のサンプルを作成するには、

Vagrantfileから以下記述を削除する。
Vagrant.require_plugin ‘my_vagrant_plugin’

そして、

Gemfileに以下記述を追加する。
group :plugins do
  gem "my_vagrant_plugin", path: "."
end

をすれば、無事!「Hello!」が表示された。

公式ドキュメントにも以下のように記述されている。

The only thing about this Gemfile that may stand out as odd is the "plugins" group and putting your plugin in that group. Because vagrant plugin commands don’t work in development, this is how you "install" your plugin into Vagrant. Vagrant will automatically load any gems listed in the "plugins" group. Note that this also allows you to add multiple plugins to Vagrant for development, if your plugin works with another plugin.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images