Skip to content

Latest commit

 

History

History
74 lines (54 loc) · 1.98 KB

vagrant.md

File metadata and controls

74 lines (54 loc) · 1.98 KB

Vagrant

Pros

  • Simplifies the spin up of a Virtual Machine, resuming it to only vagrant up. No need for manual setup of VirtualBox instances.

Cons

I can't come up with any right now. :)

Guide

For installation, follow the instructions on https://developer.hashicorp.com/vagrant/install

Cheatsheet

# spin up the VM
vagrant up
# ssh into the VM
vagrant ssh

SSH Agent forwarding

This can be useful to pull from the git repo inside the VM, so you can test deployment.

# save the ssh config to a file
vagrant ssh-config > vagrant-ssh.config
# run ssh with the file.
ssh -F vagrant-ssh.config default

Make sure you append following lines to the config file before:

Host default
   ForwardAgent yes

Sources:

Sample Vagrant file (Ubuntu 20.04)

Vagrant.configure("2") do |config|
    # Use Ubuntu 20.04 (Focal Fossa) minimal image
    config.vm.box = "ubuntu/focal64"

    # Set the hostname for the virtual machine
    config.vm.hostname = "ubuntu-minimal"

    # Forward SSH port 22 on the guest to port 2222 on the host
    config.vm.network "forwarded_port", guest: 22, host: 2222

    # Set the provider to VirtualBox
    config.vm.provider "virtualbox" do |vb|
        # Name the virtual machine
        vb.name = "UbuntuMinimalVM"

        # Allocate memory and CPUs (optional, can be customized)
        vb.memory = "1024"
        vb.cpus = 1
    end

    # Provisioning with a shell script to install basic packages (optional)
    config.vm.provision "shell", inline: <<-SHELL
        apt-get update
        apt-get upgrade -y
    SHELL
end