theJaxon / Vagrant

Contains Vagrantfiles and the related config files used to setup the machines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vagrant

Vagrant

Contains Vagrantfiles and the related config files used to setup the machines

Table of Contents generated with DocToc


Prerequisites

Basics

  • 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"

Basic commands

# 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

Networking

config.vm.network "private_network", ip: "192.168.50.210"
# Nginx let's say
config.vm.network "forwarded_port", guest: 80, host: 8080

  • Allows automatic software installation and configuration
  • 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

About

Contains Vagrantfiles and the related config files used to setup the machines


Languages

Language:Jinja 47.8%Language:Shell 35.9%Language:HCL 16.3%