February 27th 2020
Please put your hand up at any point and I’ll take questions throughout
Alex Coleman
Is this a familiar conversation?
$ vagrant init hashicorp/bionic64
$ vagrant up
$ vagrant ssh
A single script to initialize a VM
# Basic Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
end
$ vagrant box add continuumio/anaconda3
#!/usr/bin/env bash
# bootstrap.sh
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
rm -rf /var/www
ln -fs /vagrant /var/www
fi
# line in your Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
config.vm.provision :shell, path: "bootstrap.sh"
end
Switching off your Vagrant VM
$ vagrant suspend
$ vagrant halt
$ vagrant destroy
Test all this code out yourself using the vagrant_examples directory in the GitHub Repo for this presentation
https://github.com/ARCLeeds/Techtalks/tree/master/techtalk-vagrant/vagrant_examples
$ git clone https://github.com/heidemn/vagrant-bionic-desktop.git
$ cd vagrant-bionic-desktop
$ vagrant up 2>&1 | tee log.txt
$ vagrant reload
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
# line to forward active ssh agent from host to guest
config.ssh.forward_agent = true
config.vm.provision :shell, path: "bootstrap.sh"
end
$ vagrant up
...
$ vagrant ssh
...
vagrant@bionic64:~$ ls /vagrant
Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/bionic64"
# run bootstrap.sh when vagrant sets up the VM
config.vm.provision :shell, path: "bootstrap.sh"
# networking through Vagrant
config.vm.network :forwarded_port, guest: 4567, host: 4567
end
Vagrant.configure("2") do |config|
config.vm.box = "pogosoftware/ubuntu-18.04-docker"
config.vm.network "forwarded_port", guest: 8000, host: 8000
config.vm.provision "shell", inline: <<-SHELL
git clone https://github.com/datawire/hello-world.git
SHELL
end