Straw poll
Who has used vagrant before?
Getting started... install these
Notes
Clone the codehub site
git clone https://github.com/CodeHubOrg/CodeHub codehub
It's important that the folder you clone into is called 'codehub' as that is presumed later in our vagrant setup.
Clone the codehub vagrant
git clone https://github.com/CodeHubOrg/codehub-vagrant
git submodule init
git submodule update
It's important that you clone it so the codehub-vagrant and the codehub site both reside in the same directory.
Add vagrant box
vagrant box add codekipple/ubuntu-trusty32-latestpuppet ubuntu-trusty32-puppetlatest.box
vagrant box list
Use vagrant box list to see your newly added vagrant box
Normally this step can be skipped but i created a custom box for use in this workshop. [1]
Once you have downloaded it add it as an available box to vagrant
1. https://www.wetransfer.com/downloads/8d73bf346b6ee7f2c6611dca6831768020150301232619/f3cd7a208c87a3fa8ecff14983367a2920150301232619/0bdff2
Notes
Vagrant up!
Navigate into the codehub vagrant directory and get this thing started.
vagrant up
This may take some time
While that's happening I'll cover what vagrant is, why you might want to use it.
Evolution of my development environment
1. https://www.flickr.com/photos/59136411@N04/8480701963/
Notes
What is virtualisation?
Run another operating system as a guest on your host machine.
1. https://www.modern.ie/en-us/virtualization-tools
Notes
A popular use of virtualisation is testing older versions of internet explorer. [1]
Pick a provider
Notes
FIrst you going to need a tool to virtualise the guest OS. Vagrant calls these providers.
Pick a server OS
Next your going to need to decide what server OS you want to use.
Once you have downloaded one you can go through the providers GUI following the steps to create a new virtual machine.
Good news / Bad news
Vagrant is easy!
Sysadmin is hard.
Rabbit hole ahead...
Working with the VM
sudo apt-get install ...
What if you mess the VM up?
... Start again
Vagrant
Automate the creation of Virtual Machines
Vagrant reads a Vagrantfile and builds a machine based on a template called a box.
Basics
Boxes
Normally a bare set of software. An example Linux box may contain the following:
Each provider may require additional software. E.g. if you're making a box for VirtualBox, you'll want to include the VirtualBox guest additions [1] so that shared folders work properly.
Software is than provisioned on top of it. Although it does not have to work this way, you could pre install as much as you want [2]
Notes
Vagrant Cloud [1]
Notes
Vagrantfile
Configuration file read by Vagrant
Ruby based, you can use ruby syntax to assign variables and add some logic if you need it.
Vagrant command line
Notes
The docs are great [1]
Commonly used commands
What if i break my vagrant managed VM?
vagrant destroy
vagrant up
Take a break while you VM rebuilds.
Vagrant file, closer look
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "codekipple/ubuntu-trusty32-latestpuppet"
if ENV['vm_stages'] == "no"
_stages = "no"
else
_stages = "yes"
end
# Networking
config.vm.network "private_network", type: "dhcp"
# Due to some issues with the ssh keys that arises when a
# VM becomes disassociated with vagrant we are just using
# username and password for now even though it's not as secure
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder.
config.vm.synced_folder "../", "/var/www"
# Provider (VirtualBox, VMWare, ect) configuration
# Using VirtualBox:
config.vm.provider :virtualbox do |vb|
# Boot without headless mode
vb.gui = true
# Use VBoxManage to customize the VM. For example to change memory:
vb.customize ["modifyvm", :id, "--memory", "2024"]
vb.customize ["modifyvm", :id, "--cpus", "1"]
# Via http://blog.liip.ch/archive/2012/07/25/vagrant-and-node-js-quick-tip.html
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end
# Provisioning (puppet, chef, ansible, salt, .sh ect) configuration
# Using Puppet
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "base.pp"
puppet.module_path = "modules"
puppet.hiera_config_path = 'hiera/hiera.yaml' # path on host machine
puppet.working_directory = '/vagrant' # Relative path for hiera data directories
# use facter to pass a hash of variables to puppet set as facter variables
puppet.facter = {
"stages" => _stages
}
# puppet.options = "--verbose --debug"
end
end
Vagrantfile:Networking
# NAT
config.vm.network "forwarded_port",
guest: 80, host: 8080
# Host only
config.vm.network "private_network",
ip: "192.168.50.4"
# Bridged
config.vm.network "public_network"
Configures host/guest communication
Vagrantfile:Synced folders
config.vm.synced_folder "../", "/var/www"
Vagrantfile:Providers
Define your provider, pass in provider specific configuration.
# Provider (VirtualBox, VMWare, ect) configuration
# Using VirtualBox:
config.vm.provider :virtualbox do |vb|
# Boot without headless mode
vb.gui = true
# Use VBoxManage to customize the VM. For example to change memory:
vb.customize ["modifyvm", :id, "--memory", "2024"]
vb.customize ["modifyvm", :id, "--cpus", "1"]
end
Vagrantfile:Provisioners
# Provisioning (puppet, chef, ansible, salt, .sh ect) configuration
# Using Puppet
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "base.pp"
puppet.module_path = "modules"
puppet.hiera_config_path = 'hiera/hiera.yaml' # path on host machine
puppet.working_directory = '/vagrant' # Relative path for hiera data directories
end
puppet [1], chef [2], ansible [3] [4], salt [5], bash scripts .sh, Many more.
Vagrant can run multiple provisioners, each provisioner doing it's thing and then passing on to the next one [6]
Notes
Provisioning
Notes
Recommend trying ansible first. I've heard a lot of good things.
phansible.com [1] looks particularly appealing.
I went with puppet first, but i'm planning on trying ansible next to see if it works out better. Some reasons I found puppet hard.
Puppet
All configuration particular to puppet.
Getting the codehub site working
3. https://www.wetransfer.com/downloads/5bcfcb695e2265e9a738cd7c104d268820150301042603/f9839583a2ee0562ecc317a5336db42720150301042603/718577
2. http://www.rackspace.com/knowledge_center/article/how-do-i-modify-my-hosts-file
Notes
mysql -u root -ppassword codehub_dev < codehub.sql
172.28.128.3 dev.codehub.org.uk
Getting the codehub site working
Flush dns:-
Visit dev.codehub.org.uk in your browser
dscacheutil -flushcache
ipconfig /flushdns
service nscd restart
Vagrant in the wild ...
Notes
Terminology
Any questions?
Acknowledgements
Mitchell Hashimoto - Not least for creating Vagrant but also for his talk [1] on Vagrant which I used whilst creating these slides.
Notes