Getting Started:

* https://www.vagrantup.com/docs/getting-started/

Up and Running:

! Command

vagrant init hashicorp/precise64

* Create a fully-functioning Ubuntu 12.04 VM.

! Command

vagrant init bento/ubuntu-16.04

* Create a fully-functioning Ubuntu 16.04 VM.

! Command

vagrant up

* Start a VM.

! Command

vagrant ssh

* SSH into working directory's vagrant VM.

! Command

vagrant destroy

* Terminate a running vagrant VM (see "Teardown" section later for more options).

! Command

* Can completely remove the box file with this command:

vagrant box remove

Project Setup:

! Definition

A Vagrantfile is a file that marks the root directory of project and describes the kind of machine and resources that are needed to run the project as well as what software to install and how to access it.

* Many configuration options are relative to the root directory.

! Command

* Initialize directory:

vagrant init

* Vagrantfile is meant to be committed to version control.

Boxes:

! Definition

A box is a base image of a VM.

* Vagrant uses boxes to quickly clone VMs.

* Specifying the box to use is the next step after creating a new Vagrantfile.

Installing a box:

* The commands in "Up and Running" are the ones used to install a box.

! Command

* Example of adding a box:

vagrant box add hashicorp/precise64

* Stores under a name so it can be re-used by other environments.

? I think init does this already, but I'm not positive.

* Can get boxes from websites or local files.

! Website

Can get (and host) boxes from HashiCorp's Atlas box catalog.

https://atlas.hashicorp.com/boxes/search

* "Boxes are globally stored for the current user"

? I think by this they mean one Ubuntu box is recycled for all Ubuntu projects for every user, but I'm not sure.

* Projects don't modify the actual base image.

* This means that two projects using the same base image won't conflict.

Using a Box:

* Configure a box by modifying Vagrantfile.

* config.vm.box must match name used in "init" command or "box add" command.

* Can optionally specify version of a box with config.vm.box_version.

* Can optionally specify url.

                Vagrant.configure("2") do |config|
                    config.vm.box = "hashicorp/precise64"
                    config.vm.box_version = "1.1.0"
                    config.vm.box_url = "http://files.vagrantup.com/precise64.box"
                end

Synced Folders:

! /vagrant on the guest machine is shared with the directory containing Vagrantfile on the host machine.

Provisioning:

! Feature:

Using automated provisioning, vagrant will automatically install software when the VM is started.

* Installing Apache example:

* Putting this shell script as bootstrap.sh in the same directory as Vagrantfile:

                    #!/usr/bin/env bash

                    apt-get update
                    apt-get install -y apache2
                    if ! [ -L /var/www ]; then
                        rm -rf /var/www
                        ln -fs /vagrant /var/www
                    fi

* And editing the Vagrantfile:

                    Vagrant.configure("2") do |config|
                        config.vm.box = "hashicorp/precise64"
                        config.vm.provision :shell, path: "bootstrap.sh"
                    end

! Notice the "provision" line, which tells Vagrant what to do to set up the machine.

* In particular, it tells it to run the sh file.

! Command

vagrant reload --provision

* Can reload the already-running vm to use new provisions with:

* Particularly complex setups are probably not best done through provisioning, but with custom Vagrant boxes.

https://www.vagrantup.com/docs/boxes/base.html

Networking:

* Going to use networking features to give additional options for accessing guest machine from host machine.

Port forwarding:

! Feature

Port forwarding lets you share ports on guest machine through a port on the host machine.

* So the guest machine can act as a server.

* Add to Vagrantfile configuration:

config.vm.network :forwarded_port, guest: 80, host:4567

* Can now access Apache file server from host machine via localhost:4567.

* There are other options, including bridging to an existing network.

Share:

! Feature

Vagrant Share lets you share your Vagrant environment.

* I didn't really expect it to do anything different.

* Skipping details of vagrant share; not concerned about it right now.

Teardown:

Ways to discontinue VM running:

Suspending

! Command

vagrant suspend

* Saves current running state of the machine and stops it.

* Can restart with vagrant up, and will resume where left off.

* Fast.

* Uses up a lot of disk space.

* Will still be listed in VirtualBox list.

Halting

! Command

vagrant halt

* Shuts down the VM.

* Can restart with vagrant up.

* Preserves contents to disk.

* Slow.

* Will still be listed in VirtualBox list.

Destroying

! Command

vagrant destroy

* Completely removes the VM from the system-- Nothing left on disk.

* Can restart with vagrant up, but it will take longer to restart everything because it needs to be reprovisioned.

* Will no longer be listed in VirtualBox list.

! Not going beyond "Getting Started" *yet*, because think this may be enough to figure out everything else through Google. May go further in the future.

Setting static, bridged ip:

* Put this into Vagrantfile:

config.vm.network "private_network", ip: "192.168.50.4"