Vagrant Commands Cheat Sheet - DevOps Tools

Master Vagrant with our comprehensive cheat sheet. Learn essential commands for managing VMs, provisioning, and boxes. Your go-to resource for efficient Vagrant usage.

Vagrant Commands Cheat Sheet

Vagrant Command Reference

This cheat sheet provides a quick reference for essential Vagrant commands to streamline your DevOps workflow. Vagrant is a tool for building and managing virtual machine environments in a single workflow. It focuses on ease of use and automation, making it a popular choice for developers.

General Management Commands

Command Description
vagrant status Outputs the current status of the Vagrant machine.
vagrant global-status Outputs the status of all Vagrant machines managed by your user account.
vagrant global-status --prune Similar to global-status, but also removes any invalid or broken machine entries from the list.

Managing Virtual Machines (VMs)

Command Description
vagrant init Initializes a new Vagrant environment in the current directory. It creates a Vagrantfile and a .vagrant directory. You'll need to specify a base box in the Vagrantfile before running vagrant up.
vagrant up Starts and boots the Vagrant environment. If it's the first time running vagrant up, it will also trigger the provisioning process.
vagrant halt Gracefully shuts down the Vagrant virtual machine.
vagrant suspend Suspends the virtual machine, saving its current state to disk. This allows for quick resumption later.
vagrant resume Resumes a suspended virtual machine. You can also use vagrant up for this purpose.
vagrant ssh Connects to the Vagrant machine via SSH.
vagrant ssh <box_name> Connects to a specific Vagrant machine by its name, as defined in the Vagrantfile. This command can be run from any directory.
vagrant destroy Stops the Vagrant machine and removes all associated resources, including the virtual disk and network configurations.
vagrant destroy -f Destroys the Vagrant machine without prompting for confirmation. Use with caution.

VM Provisioning Commands

Command Description
vagrant provision Forces the provisioning scripts defined in the Vagrantfile to run on the already running Vagrant machine.
vagrant provision --debug Runs the provisioning process with increased verbosity, providing more detailed output for debugging.
vagrant up --provision \| tee provision.log Starts the Vagrant environment, forces provisioning, and logs all output to a file named provision.log. This is useful for capturing provisioning details.

Managing Vagrant Boxes

Command Description
vagrant box list Displays a list of all Vagrant box images currently installed on your local machine.
vagrant box add <box_name> <url> Downloads a Vagrant box image from a specified URL and adds it to your local collection.
vagrant box outdated Checks if any of your installed Vagrant boxes have newer versions available. Follow with vagrant box update to upgrade.
vagrant box remove <box_name> Deletes a specified Vagrant box image from your local machine to free up disk space.
vagrant package Packages a running Vagrant virtual machine environment into a reusable Vagrant box format. This is useful for creating custom base images.

For more in-depth information on Vagrant, refer to the official Vagrant documentation and explore resources on HashiCorp's developer portal.