A versão 1.1 do Vagrant foi lançada. A documentação que você está lendo é para o Vagrant 1.0.x. Leia mais sobre o Vagrant 1.1 no anúncio de lançamento. Acesse agora a documentação da versão 1.1.

Guest-specific Behavior

There are certain functions that Vagrant exposes which require operating system specific tasks such as shutting down gracefully, mounting folders, modifying network interfaces, etc. Vagrant abstracts these necessary functions into “guest” implementations.

There is an implementation for every major OS type such as generic Linux, Debian, Ubuntu, FreeBSD, etc.

This topic is for advanced users

The following topic is for advanced users. The majority of Vagrant users will never have to know about this.

Tasks

The following is a list of tasks which are delegated to guest classes:

  • Halting - Shutting down the machine gracefully
  • Mounting Shared Folders - Creating, mounting, and setting up the permissions for shared folders.
  • Configuring Network Interfaces - Configuring network interfaces via static configuration, DHCP, etc.

This list will surely grow as Vagrant grows. For now, to implement a custom operating system implementation, only the above two features need to be implemented.

Creating a New Guest Implementation

Creating a new guest implementer is quite simple: Inherit from Vagrant::Guest::Base and implement the stubbed method on that class. Instead of going over each method here, I’ll point you to the base source file which is thoroughly commented to explain each method. It’s also recommended you view the linux guest to get an idea of what an implementation looks like.

Using a New Guest Implementation

The new guest implementation should be specified as the config.vm.guest configuration value. By default, this is :linux. A symbol represents a built-in guest type. For your custom types, you should set the value as the class name for your new implementation. Below is a sample Vagrantfile which does just this:

# An example guest:
require 'bsd_guest'

Vagrant::Config.run do |config|
  # Set the guest to the proper class name:
  config.vm.guest = BSDGuest
end

The configured Vagrant environment will then use the custom guest implementation.