Search for a command to run...
Comprehensive guide for installing and using Vagrant, a tool for building and managing virtual machine environments in a single workflow, with support for VirtualBox, VMware, and other providers.
Vagrant is a tool for building and managing virtual machine environments in a single workflow. It provides easy to configure, reproducible, and portable work environments.
# Add HashiCorp GPG key
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
# Add HashiCorp repository
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
# Update and install Vagrant
sudo apt update
sudo apt install vagrant
# Install VirtualBox (if needed)
sudo apt install virtualbox
# Create and enter project directory
mkdir my_vagrant_project
cd my_vagrant_project
# Initialize Vagrant project
vagrant init hashicorp/bionic64
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.cpus = 2
end
end
# Start VM
vagrant up
# SSH into VM
vagrant ssh
# Stop VM
vagrant halt
# Destroy VM
vagrant destroy
# Check status
vagrant status
Vagrant.configure("2") do |config|
config.vm.define "web" do |web|
web.vm.box = "ubuntu/focal64"
web.vm.network "private_network", ip: "192.168.33.10"
end
config.vm.define "db" do |db|
db.vm.box = "ubuntu/focal64"
db.vm.network "private_network", ip: "192.168.33.11"
end
end
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
# Shell provisioning
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y nginx
SHELL
# Ansible provisioning
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
end
end
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
# Basic synced folder
config.vm.synced_folder ".", "/vagrant"
# NFS synced folder (better performance)
config.vm.synced_folder ".", "/vagrant", type: "nfs"
end
# Add a box
vagrant box add ubuntu/focal64
# List boxes
vagrant box list
# Update boxes
vagrant box update
# Remove boxes
vagrant box remove ubuntu/focal64
# Package current VM as a box
vagrant package --output custom.box
# Add custom box
vagrant box add my-custom-box custom.box
# List installed plugins
vagrant plugin list
# Install a plugin
vagrant plugin install vagrant-vbguest
# Update plugins
vagrant plugin update
# Uninstall plugin
vagrant plugin uninstall vagrant-vbguest
# VirtualBox Guest Additions
vagrant plugin install vagrant-vbguest
# AWS provider
vagrant plugin install vagrant-aws
# Automatic box updates
vagrant plugin install vagrant-vbguest
Network Issues
# Reset network
vagrant reload
# Check network status
vagrant ssh -c "ip addr"
Provider Issues
# Check provider status
vagrant status
# Debug provider
VAGRANT_LOG=debug vagrant up
Synced Folder Issues
# Reinstall VirtualBox Guest Additions
vagrant plugin install vagrant-vbguest
vagrant vbguest
SSH Issues
Resource Issues
Project Organization
Performance
Security
Complete guide for installing and configuring HashiCorp Consul, a service networking platform that provides service discovery, configuration, and segmentation functionality.
Detailed instructions for installing and using HashiCorp Packer, an open-source tool for creating identical machine images for multiple platforms from a single source configuration.