How to use a conditional to determine if a plugin is available?

Howdy. I’d like to be able to write a conditional in a Vagrantfile that allows me to check if a particular plugin (or a method that would be available from the plugin) is available.

Some pseudocode to demonstrate what I’m looking for:

if config.dns then
   <do some 'vagrant-dns' plugin stuff>

My goal is to make my Vagrantfile not be brittle, and handle OSes where the ‘vagrant-dns’ plugin is not supported. It should create the host, but just omit configuring DNS resolution for the guest.

Happy to show more about the intended use case. Thanks in advance for your help.

Cheers! And thanks for Vagrant!

Hi there,

I believe this should get you what you’re after:

if Vagrant::Plugin::Manager.instance.plugin_installed?("vagrant-dns")
  ... # do vagrant-dns plugin stuff
end
1 Like