vagrant hands on workshop for beginners
TRANSCRIPT
whoami
Mother of 3 girls 22,18,13
Software developer 3 years
ALM Expert 20+ years
DevOps Enthusiast 3 years
Owner of L.M.B.-Consulting Ltd. since 1999
IBM Advanced Business Partner ~10 years
https://www.linkedin.com/in/lioramilbaum
Vagrant introduction
VirtualBox introduction
Vagrant+Virtualbox workflow
Getting base boxes
Configuring boxes
Provisioning - shell
Agenda
Vagrant introduction
VirtualBox introduction
Vagrant+Virtualbox workflow
Getting base boxes
Configuring boxes
Provisioning - shell
Agenda
What is Vagrant good for?
Create and configure lightweight, reproducible
and portable development environments
https://www.vagrantup.com/
Vagrant in high level
Command line tool
Automates VM creation: Virtualbox, VMWare,
Hyper-V, AWS….
Integrates with configuration management
tools: shell, chef, Ansible, Puppet….
Runs on: Linux, Windows, MacOS
Why use Vagrant?
Create new VMs quickly and easily
Keep the number of VMs under control
Reproducibility
Identical environment in dev/test/stage/prod
Portability
Vagrant introduction
VirtualBox introduction
Vagrant+Virtualbox workflow
Getting base boxes
Configuring boxes
Provisioning - shell
Agenda
What is VirtualBox good for?
A general purpose full virtualizer for x86
hardware
https://www.virtualbox.org
Vagrant introduction
VirtualBox introduction
Vagrant+Virtualbox workflow
Getting base boxes
Configuring boxes
Provisioning - shell
Agenda
What happened under the hood
$ vagrant init hashicorp/precise32
A Vagrantfile is createdVAGRANTFILE_API_VERSION = ‘2’
vagrant.configure(VAGRANTFILE_API_VERSION) do |config|config.vm.box = ‘hashicorp/precise32’
end
What happened under the hood
$ vagrant up
The base box is downloaded and stored locally
in ~/.vagrant.d/boxes
A new VM is created and configured with the base box as
a template
The VM is booted
The box is provisioned
Vagrant introduction
VirtualBox introduction
Vagrant+Virtualbox workflow
Getting base boxes
Configuring boxes
Provisioning - shell
Agenda
Using another base box
$ vagrant box add hashicorp/precise64 & Update Vagrantfile
or
$ vagrant init hashicorp/precise64
Vagrantfile after
VAGRANTFILE_API_VERSION = ‘2’
vagrant.configure(VAGRANTFILE_API_VERSION) do |config|config.vm.box = ‘hashicorp/precise64’
end
Vagrant introduction
VirtualBox introduction
Vagrant+Virtualbox workflow
Getting base boxes
Configuring boxes
Provisioning - shell
Agenda
Modified VM
VAGRANTFILE_API_VERSION = ‘2’
vagrant.configure(VAGRANTFILE_API_VERSION) do |config|config.vm.box = ‘hashicorp/precise64’
config.vm.provider :virtualbox do |vb|vb.name = HOST_NAMEvb.customize [‘modifyvm’, :id, ‘--memory’, 256]
endend
$ vagrant init user/box # Create Vagrantfile for specified
base box
$ vim/notepad Vagrantfile # Customize your box
$ vagrant up # Create VM if needed and boot
$ vagrant reload # After every change to Vagrantfile
$ vagrant halt # Poweroff
$ vagrant destroy # Clean up!
$ vagrant ssh # log in
$ vagrant status # Status of your VM
Summery
Vagrant introduction
VirtualBox introduction
Vagrant+Virtualbox workflow
Getting base boxes
Configuring boxes
Provisioning - shell
Agenda
Shell Provisioning
Add to your Vagrantfile
config.vm.provision 'shell', path: 'provision.sh'
Put the script into the same folder as
Vagrantfile
Recommended workflow
First do the installation manually (vagrant ssh)
Make sure every command runs without user interaction!
Record every command in the script
If everything works: vagrant destroy -f && vagrant up