» Plugin Development: Provisioners

This page documents how to add new provisioners to Vagrant,allowing Vagrant to automatically install software and configure softwareusing a custom provisioner. Prior to reading this, you should be familiarwith the plugin development basics.

Warning: Advanced Topic! Developing plugins is anadvanced topic that only experienced Vagrant users who are reasonablycomfortable with Ruby should approach.

» Definition Component

Within the context of a plugin definition, new provisioners can be definedlike so:

  1. provisioner "custom" do
  2. require_relative "provisioner"
  3. Provisioner
  4. end

Provisioners are defined with the provisioner method, which takes asingle argument specifying the name of the provisioner. This is thename that used with config.vm.provision when configuring and enablingthe provisioner. So in the case above, the provisioner would be enabledusing config.vm.provision :custom.

The block argument then lazily loads and returns a class that implementsthe Vagrant.plugin(2, :provisioner) interface, which is covered next.

» Provisioner Class

The provisioner class should subclass and implementVagrant.plugin(2, :provisioner) which is an upgrade-safe way to letVagrant return the proper parent class for provisioners.

This class and the methods that need to be implemented arevery well documented.The documentation on the class in the comments should be enoughto understand what needs to be done.

There are two main methods that need to be implemented: theconfigure method and the provision method.

The configure method is called early in the machine booting processto allow the provisioner to define new configuration on the machine, suchas sharing folders, defining networks, etc. As an example, theChef solo provisioneruses this to define shared folders.

The provision method is called when the machine is booted and readyfor SSH connections. In this method, the provisioner should executeany commands that need to be executed.