Contains Vagrantfiles and the related config files used to setup the machines
Table of Contents generated with DocToc
- Start by downloading VirtualBox (This will be used as our provider)
- After that Install Vagrant software
- The package format for Vagrant environments where we specify a box environment and OS in the Vagrantfile
- It's better to also specify the exact box version just to avoid any breaking changes that might happen (Don't use latest)
config.vm.box = "ubuntu/jammy64"
config.vm.box_version = "20220718.0.1"
- Enable Vagrant to sync a folder on the host machine to the guest machine, allowing you to continue working on your project's files on your host machine, but use the resources in the guest machine to compile or run your project.
- We stick to the default and use
/vagrant
as the directory that will be synced
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
# Bring up the machines specified in Vagrantfile
# Downloads Vagrant boxes if not found
# https://developer.hashicorp.com/vagrant/docs/cli/up
vagrant up
# Restart Vagrant machines
# The equivalent of running a halt followed by an up
# https://developer.hashicorp.com/vagrant/docs/cli/reload
vagrant reload
# Re-Provision the machines (re-exectues using whatever specified provisioner - ex: bash, ansible)
# Executed on a running environment
# https://developer.hashicorp.com/vagrant/docs/cli/provision
vagrant provision
# SSH Into the machine (If only one machine in use then no need for name)
# https://developer.hashicorp.com/vagrant/docs/cli/ssh
vagrant ssh
# If more than one machine exists then specify the name
vagrant ssh <name>
# Take a snapshot from the machine to be restored at any point in the future
# https://developer.hashicorp.com/vagrant/docs/cli/snapshot
vagrant snapshot save <name>
# Restore from the snapshot
vagrant snapshot restore <name>
# Shut down the VM
# https://developer.hashicorp.com/vagrant/docs/cli/halt
vagrant halt
# Destroy the environment
# After running this command, your computer should be left at a clean state, as if you never created the guest machine in the first place.
# https://developer.hashicorp.com/vagrant/docs/cli/destroy
vagrant destroy -f
- Private networks allows guest machine access with an address that's not publicly accessible (the address is within private address space)
- Vagrant Cloud is what you can consider the equivalent of Dockerhub, just a place to fetch the needed Vagrant Boxes from
- Some quality Vagrant boxes are being maintained by the Bento Project
config.vm.network "private_network", ip: "192.168.50.210"
- Allows accessing specific port on the vagrant machine by mapping it to another port on the host OS
- Example - a web server listening on port 80 can have forwarded port mapping to port 8080
# Nginx let's say
config.vm.network "forwarded_port", guest: 80, host: 8080
- Allows automatic software installation and configuration
- Allows executing a script on the vagrant machine
- Can be
inline
script where it's declared inside the Vagrantfile - Supports
path
where you point to shell script location and it gets executed
- Doesn't require any additional software on host OS
- Ansible gets installed automatically on the guest machine
- Allows ansible playbooks execution on the vagrant machine