Using Popular Vagrant Plugins
1. Using vagrant-vbguest
The vagrant-vbguest plugin automatically manages VirtualBox Guest Additions on Vagrant boxes, ensuring compatibility between the host and guest systems.
| Command | Description | Notes |
|---|---|---|
| vagrant plugin install vagrant-vbguest | Installs the vagrant-vbguest plugin | Required before usage |
| vagrant vbguest | Checks and installs guest additions if needed | Runs automatically during vagrant up |
| vagrant vbguest --no-install | Checks version without installing | Useful for debugging |
Example: Installing and using vagrant-vbguest
vagrant plugin install vagrant-vbguest
vagrant up
vagrant vbguest --status
2. Using vagrant-disksize
The vagrant-disksize plugin allows you to increase the disk size of your Vagrant VMs, which is particularly useful when working with large datasets or applications that require more storage than the default allocation.
| Configuration Option | Description | Default Value | Notes |
|---|---|---|---|
| vagrant_disksize.size | Specifies the new disk size in gigabytes. | 10GB |
Must be a positive integer. The size will be rounded up to the nearest whole gigabyte. |
Example: Configuring Disk Size
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
# Increase disk size to 20GB
config.disksize.size = "20GB"
end
vagrant-disksize plugin requires VirtualBox or VMware Fusion/Workstation to function. It does not support Hyper-V or other hypervisors.
3. Using vagrant-hostmanager
The vagrant-hostmanager plugin automatically manages the /etc/hosts file on both the host machine and guest VMs, making it easy to access VMs by hostname instead of IP address.
| Option | Values | Notes |
|---|---|---|
| config.hostmanager.enabled | true |
Enables the plugin |
| config.hostmanager.manage_host | true |
Manage host machine's /etc/hosts |
| config.hostmanager.manage_guest | true |
Manage guest VM's /etc/hosts |
| config.hostmanager.ip | 192.168.56.10 |
IP address to use for hostnames |
Example: Basic Configuration
# Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.network "private_network", ip: "192.168.56.10"
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = true
end
vagrant-hostmanager to be installed via vagrant plugin install vagrant-hostmanager.
/etc/hosts may require elevated privileges (e.g., sudo). Ensure the plugin has appropriate permissions.
Key Features
- Automatically adds entries to
/etc/hosts - Supports multiple VMs with unique hostnames
- Works with private_network and public_network configurations
4. Using vagrant-cachier
The vagrant-cachier plugin optimizes Vagrant environments by caching package downloads and sharing them across multiple VMs, significantly reducing download times.
| Configuration Option | Description | Default Value |
|---|---|---|
| config.cache.enable | Enables or disables the cache functionality. | false |
| config.cache.auto_detect | Automatically detects the package manager to use for caching. | true |
| config.cache.box | Enables caching of packages from the base box. | false |
Example: Enabling vagrant-cachier
Vagrant.configure("2") do |config|
config.cache.enable = true
config.cache.auto_detect = true
end
vagrant-cachier plugin caches packages in a shared directory, which is typically located at ~/.vagrant.d/. Ensure sufficient disk space and appropriate permissions for this directory.
5. Using vagrant-env
The vagrant-env plugin allows you to manage environment variables for your Vagrant environment. It provides a simple way to set, get, and list environment variables that are available within the Vagrant VM.
| Command | Description | Example |
|---|---|---|
| vagrant env set <key> <value> | Sets an environment variable | vagrant env set DATABASE_URL postgres://localhost:5432/mydb |
| vagrant env get <key> | Gets the value of an environment variable | vagrant env get DATABASE_URL |
| vagrant env list | Lists all environment variables | vagrant env list |
Example: Setting and Using Environment Variables
vagrant env set NODE_ENV development
vagrant env set API_KEY abc123def456
Example: Retrieving Environment Variables
vagrant env get NODE_ENV
# Output: development
vagrant env list
# Output:
# NODE_ENV=development
# API_KEY=abc123def456
6. Using vagrant-reload
| Option | Values | Notes |
|---|---|---|
| config.vm.provision | "reload" |
Provisioner name for vagrant-reload |
| config.vm.provision.reload | true |
Enable reload provisioner |
vagrant-reload plugin allows you to reload the VM after provisioning, which is useful for applying configuration changes that require a reboot.
7. Using vagrant-share
The vagrant-share plugin allows you to share your Vagrant environment with others over the internet. This is useful for collaboration, demos, or providing access to a development environment.
| Command | Description | Notes |
|---|---|---|
| vagrant share | Starts sharing the Vagrant environment | Requires a valid Vagrant Cloud account and authentication |
| vagrant share --help | Displays help for the vagrant share command | Lists all available options and usage examples |
vagrant share command requires the Vagrant Cloud account to be authenticated. You must run vagrant login before using this command.
8. Using vagrant-scp
| Option | Values | Notes |
|---|---|---|
| vagrant scp | vagrant scp <source> <destination> |
Copy files between host and guest machine |
| vagrant scp --help | vagrant scp --help |
Display help for vagrant scp command |
vagrant scp command requires the vagrant-scp plugin to be installed and enabled.
9. Using vagrant-hostsupdater
The vagrant-hostsupdater plugin automatically manages the /etc/hosts file on your host machine to map Vagrant box names to IP addresses. This is particularly useful for local development environments where you want to access your Vagrant boxes via custom domain names.
| Option | Values | Description |
|---|---|---|
| vagrant hostsupdater | enable |
Enables the plugin for the current Vagrant environment. |
| vagrant hostsupdater | disable |
Disables the plugin for the current Vagrant environment. |
Example: Basic Vagrantfile Configuration
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.network "private_network", ip: "192.168.56.10"
config.vm.hostname = "myapp.local"
# Enable vagrant-hostsupdater
config.hostsupdater.aliases = ["myapp.local", "api.myapp.local"]
end
/etc/hosts file for the configured hostnames and IP addresses. Ensure you have appropriate permissions to modify this file.
sudo if the plugin fails to update the hosts file due to permission restrictions.
Key Features
- Automatically updates
/etc/hostswith Vagrant box IP addresses. - Supports custom hostnames via
config.vm.hostname. - Allows defining additional aliases using
config.hostsupdater.aliases. - Works with private network configurations.
10. Evaluating Plugin Compatibility
| Plugin | Compatible Vagrant Versions | Notes |
|---|---|---|
| vagrant-vsphere | >= 2.0.0 |
Supports vSphere hypervisor integration |
| vagrant-digitalocean | >= 2.1.0 |
For DigitalOcean droplet management |
| vagrant-azure | >= 2.0.0 |
Enables Azure VM provisioning |
| vagrant-libvirt | >= 2.0.0 |
Supports KVM/QEMU virtualization |
| vagrant-docker | >= 2.0.0 |
Integrates Docker container support |