LoginSignup
2
3

More than 5 years have passed since last update.

Vagrant プラグインがインストール済みかどうかVagrantfile でチェックする

Posted at

必要なプラグインをインストールせずに vagrant up など実行すると原因のわかりづらいエラーメッセージ(Message: NameError: uninitialized constant Aws 等)で止まる。ちょっとだけ親切にしたいと思ってVagrantfile 内でプラグインのインストール状態をチェックする様にしました。

Vagrant#has_plugin? を使うとプラグインがインストール済みかチェックできます。Vagrantfile にRuby コードをそのまま書けるので、こんな感じで書いてます。

Vagrantfile
plugins = %w(
  aws-sdk
  vagrant-aws
).reject { |name| Vagrant.has_plugin?(name) }
fail "plugins not found!\nRun `vagrant plugin install #{plugins.join(' ')}`." unless plugins.empty?

下記の内容を参考にやっつけ仕事しました。
Demand a Vagrant plugin within the Vagrantfile? - Stack Overflow

プラグインのインストールを自動化したい

vagrant-multiplug というVagrantのプラグインを使うと vagrant up する時に自動的にインストールするように設定できるみたいです。

2
3
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
2
3