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.
The following topic is for advanced users. The majority of Vagrant users will never have to know about this.
The following is a list of tasks which are delegated to guest classes:
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 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.
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.