2. About Me
@michaelpeacock
Head Developer @ Ground Six
Leading the development team and managing the
development process
We are a tech investment company: you bring ideas, we
partner and build the product
Author
Occasional Speaker
5. Virtualisation
Abstraction layer for your hardware
Lets multiple Operating Systems run concurrently, each
running on their own virtual hardware
6. Virtualisation
Abstraction layer for your hardware
Lets multiple Operating Systems run concurrently, each
running on their own virtual hardware
Limited by your own physical hardware and your host
machine
13. Vagrant
www.vagrantup.com
“Create and configure lightweight, reproducable, and
portable development environments”
Set of command line tools which interacts with and
automates VirtualBox
14. Vagrant
www.vagrantup.com
“Create and configure lightweight, reproducable, and
portable development environments”
Set of command line tools which interacts with and
automates VirtualBox
Designed around portability
17. Why?
Quick start time for new team members
Vagrant up: you have a development environment
18. Why?
Quick start time for new team members
Vagrant up: you have a development environment
Server configuration can be version controlled
19. Why?
Quick start time for new team members
Vagrant up: you have a development environment
Server configuration can be version controlled
Cross-platform: work from any machine
20. Why?
Quick start time for new team members
Vagrant up: you have a development environment
Server configuration can be version controlled
Cross-platform: work from any machine
Work on multiple projects? Easy to pickup an old, legacy
project with its funky server configs
21. Why?
Quick start time for new team members
Vagrant up: you have a development environment
Server configuration can be version controlled
Cross-platform: work from any machine
Work on multiple projects? Easy to pickup an old, legacy
project with its funky server configs
Can run multiple VMs independently
22. Why?
Quick start time for new team members
Vagrant up: you have a development environment
Server configuration can be version controlled
Cross-platform: work from any machine
Work on multiple projects? Easy to pickup an old, legacy
project with its funky server configs
Can run multiple VMs independently
Doesn’t mess with your local, host machine
32. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
33. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
34. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
35. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
36. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
37. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
38. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
39. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
40. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
41. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
42. 3 lines: up and running
# download a “base” VM image and give it the name
# base for future use
vagrant box add base http://files.vagrantup.com/
precise64.box
# Initialise a new vagrant project
# i.e. create a new vagrant file
vagrant init
# Boot the VM based off the config file we created
vagrant up
51. Whats happened?
Downloaded a base box of Ubuntu, configured for
vagrant
Created a new project
Configured to use this base box by default
52. Whats happened?
Downloaded a base box of Ubuntu, configured for
vagrant
Created a new project
Configured to use this base box by default
Booted the VM: vagrant up
53. Whats happened?
Downloaded a base box of Ubuntu, configured for
vagrant
Created a new project
Configured to use this base box by default
Booted the VM: vagrant up
Connected into the VM: vagrant ssh
68. vagrant destroy: a warning
The VM is completely wiped
Anything that can’t be replicated from:
Your project folder (shared folder)
Vagrant base box
Vagrant File
Puppet Manifests
69. vagrant destroy: a warning
The VM is completely wiped
Anything that can’t be replicated from:
Your project folder (shared folder)
Vagrant base box
Vagrant File
Puppet Manifests
WILL BE LOST FOREVER
E.g. Databases (hint: use a DB patching or versioning tool in your
project folder)
70. vagrant init
Creates a new Vagrantfile, which instructs
vagrant what too boot and how to do it. Let’s
take a peak.
71. # -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "base"
end
72. Box to use
# use the box called base
config.vm.box = "base"
# Fallback URL, if we don't have a box called base, download from here
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
74. Networking
Host only
VM is only visible to the host machine
config.vm.network :hostonly, "192.168.33.10"
75. Networking
Host only
VM is only visible to the host machine
config.vm.network :hostonly, "192.168.33.10"
Bridged
Network connection to the VM is bridged, letting it
appear as a device on the network
config.vm.network :bridged
87. What can Puppet do
Checks conditions:
Package installed
File exists / contains / etc
88. What can Puppet do
Checks conditions:
Package installed
File exists / contains / etc
Exec: Run an ad-hock command*
* doesn’t sit well with Puppets “checking” nature.
Execs get re-run (unless you use special conditions) on
vagrant up
102. Multiple VMs
Within the vagrantfile, we can define multiple VMs
E.g. need a separate VM for web and db server to
mimic production environment?
Vagrant::Config.run do |config|
config.vm.define :web do |web_config|
web_config.vm.box = "web"
web_config.vm.forward_port 80, 8080
end
config.vm.define :db do |db_config|
db_config.vm.box = "db"
db_config.vm.forward_port 3306, 3306
end
end
105. Exporting Box
Always using the same stack / versions on your box?
Slow un-reliable Internet connection means puppet
takes an age to run? Export the base box with these
pre-installed
vagrant package
106. Creating your own box
Virtualbox configured:
Guest additions
SSH & key based authentication for the vagrant user
Ruby, RubyGems, Puppet and Chef
Export the box
vagrantup.com/v1/docs/base_boxes.html
109. Caveats
Funky permissions
Files created on the host shared folder show without permissions on the
guest and are inaccessible
Solution: upgrade virtualbox guest additions on guest
110. Caveats
Funky permissions
Files created on the host shared folder show without permissions on the
guest and are inaccessible
Solution: upgrade virtualbox guest additions on guest
Can’t chmod files within shared folder
config.vm.share_folder("v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777')
Thanks @AnthonySterling & @ChrisDKemper
111. Caveats
Funky permissions
Files created on the host shared folder show without permissions on the
guest and are inaccessible
Solution: upgrade virtualbox guest additions on guest
Can’t chmod files within shared folder
config.vm.share_folder("v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777')
Thanks @AnthonySterling & @ChrisDKemper
Waiting for VM to boot
Open VirtualBox
Cancel, halt the VM and try again
112. Caveats
Funky permissions
Files created on the host shared folder show without permissions on the
guest and are inaccessible
Solution: upgrade virtualbox guest additions on guest
Can’t chmod files within shared folder
config.vm.share_folder("v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777')
Thanks @AnthonySterling & @ChrisDKemper
Waiting for VM to boot
Open VirtualBox
Cancel, halt the VM and try again