Vagrant
Updated: February 11, 2024
Creates developer environments inside Virtual Machines (VMs)
Vagrant is crossplatform.
Table of Contents
* [tldr](#tldr)
* [Setup](#setup)
* [Autocompletion](#auto)
* [Arguments](#arguments)
* [Config](#config)
TLDR
# help for a specific command
vagrant <command> -h
# create a vagrant file in current directory
vagrant init
# start and provision a vagrant environment
vagrant up
# shutdown VM while keeping in tact
vagrant suspend
# boot up VM after a shutdown
vagrant resume
# make config changes apply > same as running halt then up
vagrant reload
# ssh into machine
vagrant ssh
# stops a running machine and and destroy all resources except the box
vagrant destroy -g # --graceful shutdown graceful before destroying
# remove boxes
vagrant box list # show boxes on system
vagrant box remove <box>
SETUP
In order to create VMs Hyper-V must be enable in these 2 places: 1. Bios > For gigabytle is listed under Tweaker > Advanced CPU Settings > SVM Mode {enable} 2. In Windows Powershell (run as admin)
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
It will ask for a restart hopefully, if it doesn’t, restart the PC.
AUTOCOMPLETION
# enable by running:
vagrant autocomplete install --bash --zsh
ARGUMENTS
CONFIG
# Networking
config.vm.network :private_network, type: "dhcp" # get ip automatically
config.vm.network :private_network, ip: "192.168.60.40" # set ip statically
config.vm.network :public_network # get ip on hosts network
config.vm.network "forwarded_port", guest: 80, host: 8080, # forward port 80 in the guest to host on 8080
auto_correct: true # finds an unused port if 8080 is used or conflicted
config.vm.usable_port_range = (2200..2250) # Set a port range for auto correct
When using YAML there are two scalars for long commands involving modules like shell:
the > is a folded scalar for single line use
while | is a multiline scalar for, well, multiple lines.