Search code examples
vagrant

Demand a Vagrant plugin within the Vagrantfile?


Supposed execution of a Vagrantfile requires a specific Vagrant plugin to be installed. So, basically what you need to do is

$ vagrant plugin install foobar-plugin
$ vagrant up

If you skip the first step, vagrant up fails.

Is there an option in Vagrant to make it install the plugin automatically? In other words: Is it possible to specify within a Vagrantfile which plugins to install automatically before creating and booting up the machine?


Solution

  • 2019 Update: Vagrant now has functionality to require plugins through the Vagrantfile via:

    Vagrant.configure("2") do |config|
      config.vagrant.plugins = "vagrant-some-plugin"
    
      # or as array:
      config.vagrant.plugins = ["vagrant-some-plugin", "vagrant-some-other-plugin"]
    
      # or as hash
      config.vagrant.plugins = {"vagrant-some-plugin" => {"version" => "1.0.0"}}
    end
    

    If Vagrant detects there are plugins not already installed it will prompt the user to install them itself:

    $ vagrant up
    Vagrant has detected project local plugins configured for this
    project which are not installed.
    
      vagrant-some-plugin
    Install local plugins (Y/N) [N]: y
    Installing the 'vagrant-some-plugin' plugin. This can take a few minutes...
    Fetching vagrant-some-plugin-1.0.0.gem
    Installed the plugin 'vagrant-some-plugin (1.0.0)'!
    
    
    Vagrant has completed installing local plugins for the current Vagrant
    project directory. Please run the requested command again.
    

    See https://www.vagrantup.com/docs/vagrantfile/vagrant_settings.html