» Plugin Development: Host Capabilities

This page documents how to add new capabilities for hoststo Vagrant, allowing Vagrant to perform new actions on specific hostoperating systems.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.

Host capabilities augment hosts by attachingspecific "capabilities" to the host, which are actions that can be performedin the context of that host operating system.

The power of capabilities is that plugins can add new capabilities toexisting host operating systems without modifying the core of Vagrant.In earlier versions of Vagrant, all the host logic was contained in thecore of Vagrant and was not easily augmented.

» Definition and Implementation

The definition and implementation of host capabilities is identicalto guest capabilities.

The main difference from guest capabilities, however, is that instead oftaking a machine as the first argument, all host capabilities take aninstance of Vagrant::Environment as their first argument.

Access to the environment allows host capabilities to access global state,specific machines, and also allows them to call other host capabilities.

» Calling Capabilities

Since you have access to the environment in every capability, capabilities canalso call other host capabilities. This is useful for using the inheritancemechanism of capabilities to potentially ask helpers for more information.For example, the "linux" guest has a "nfs_check_command" capability thatreturns the command to use to check if NFS is running.

Capabilities on child guests of Linux such as RedHat or Arch use thiscapability to mostly inherit the Linux behavior, except for this minordetail.

Capabilities can be called like so:

  1. environment.host.capability(:capability_name)

Any additional arguments given to the method will be passed on to thecapability, and the capability will return the value that the actualcapability returned.