Reproducible and Portable
Work Environments with
Vagrant and Chef
About Me
• 33 years old, almost married
• From Karlsruhe, Germany
• Studied Computer Science
• Hobbies: guitar, climbing,
...
Outline
• Motivation
• Introducing Vagrant & Chef

• Vagrant „Hands-On“
• Advanced usage
Motivation
• Internal project
• Estimated development time ~2 years
• Approx. 15 developers
• 2-day sprints, every second ...
Motivation
Observations
• Setting up dev environment takes > 1 day
– More than ½ of the sprint time!

• Developers spent t...
Solution: Vagrant Boxes
Provisioning 2 virtual machines...
• ...each with an extended LAMP stack*)

• ...with 4 different ...
Technological Stack
VirtualBox
Free open source virtualization tool
Chef
Automation tool for
Configuration Management

Vag...
What is Vagrant?
• Building tool for portable work environments
• Tool for distributing work environments
• Written in Rub...
Vagrant Components
• Vagrant Box
• Vagrantfile
• Provisioners
• Providers
Vagrant Boxes
• Pre-installed base images
• Used as base layer for all further provisioning
• Many different boxes availab...
The Vagrantfile
• Marks root directory of Vagrant project
• Describes what Vagrant box to use

• Describes settings of box...
Provisioners
• Configures your Vagrant box by
– Installing packages and software
– Configuration and starting of services
...
Providers
• Describe in which virtualization environment

to provision your machines
• Multiple providers available
– Virt...
What is Chef?
• Configuration Management automation tool
• Written in Ruby

• „Code your desired system state“
• Put syste...
Chef Architecture
Chef Architecture
Using chef-solo
• mount cookbooks directory into your box
config.vm.synced_folder "./chef", "/var/chef"
config.vm.synced_f...
The solo.rb File
• Define some paths:
file_cache_path "/var/chef-cache"
cookbook_path ["/var/chef/cookbooks”]
data_bag_pat...
The config.json File
• Define cookbook runlist:
{"run_list" : ["recipe[cookbook_name]"]}

• Further configuration in confi...
Chef Provisioning Alternatives
• Different ways for Chef provisioning
– Mounting Cookbooks and use chef-solo

– Copy Cookb...
Overview
2

Chef Cookbooks
/home/vagrant/chef

mounted/copied into
OR taken from chef server

Vagrant Box

4

uses
cookboo...
Provisioning Activity

Provisioning Activity
Provision Projects

Configuration
Management
Booting Box
Set up Box

Chef,
Gi...
Set Up Box
1. Install VirtualBox & Vagrant
2. Add a box
vagrant box add box_name http://box_url

1. Create a first Vagrant...
Set up & Boot the Box
4. Use the box in your Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "box_name"
end...
Versioning and Distribution
• Remember: „Everything should be put into
Version Control!“
• Vagrantfile can easily be put i...
Daily Vagrant Usage
• Start the box
vagrant up

• Stop the box
Vagrant halt

• Suspend the box
vagrant suspend

• Resume t...
Multiple Boxes for Multiple Projects
PROs
- Easy to set up
- Can have different systems in a box

Vagrant Box
Project 1

V...
Multiple Projects in one Box
PROs
- Less ressources required

Vagrant Box
Project 1
Project 2
Project 3

CONs
- No easy wa...
Identical Copy of Server
server is provisioned
using Chef Client

Chef Client

Chef Server

Chef Cookbooks

mounted/copied...
Vagrant & Chef for CI / CD

• Set up the whole deployment chain locally
• Use tools like Jenkins inside your boxes
• Provi...
DevOps
• Tools like Vagrant and Chef bring Developers
and system operators closer together

• Learn from each other
• Use ...
Summary
• Vagrant is a great tool for portable boxes
• Chef can help you manage your configuration
• „Infrastructure as Co...
Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014
Vagrant and Chef on FOSSASIA 2014
Upcoming SlideShare
Loading in …5
×

Vagrant and Chef on FOSSASIA 2014

1,496 views
1,314 views

Published on

This presentation gives a short introduction to Vagrant and Chef for automation of configuration management. You will get a first overview of the stack of technology used to set up your own Vagrant Boxes and how they help the to build reliable development environments right on your own local laptop. We will scratch topics like DevOps and Continuous Integration and how they link to Configuration Management and Chef and Vagrant.

If you like these slides, make sure to check out http://de.slideshare.net/Sebobo/continuous-delivery-with-open-source-tools as well!

Published in: Technology
1 Comment
7 Likes
Statistics
Notes
No Downloads
Views
Total views
1,496
On SlideShare
0
From Embeds
0
Number of Embeds
93
Actions
Shares
0
Downloads
46
Comments
1
Likes
7
Embeds 0
No embeds

No notes for slide

Vagrant and Chef on FOSSASIA 2014

  1. 1. Reproducible and Portable Work Environments with Vagrant and Chef
  2. 2. About Me • 33 years old, almost married • From Karlsruhe, Germany • Studied Computer Science • Hobbies: guitar, climbing, cycling, travel, photography • Works in Phnom Penh for 3 months • Working with TYPO3
  3. 3. Outline • Motivation • Introducing Vagrant & Chef • Vagrant „Hands-On“ • Advanced usage
  4. 4. Motivation • Internal project • Estimated development time ~2 years • Approx. 15 developers • 2-day sprints, every second week • 4 developers per sprint
  5. 5. Motivation Observations • Setting up dev environment takes > 1 day – More than ½ of the sprint time! • Developers spent too much time on setup • Always needed physical server for testing
  6. 6. Solution: Vagrant Boxes Provisioning 2 virtual machines... • ...each with an extended LAMP stack*) • ...with 4 different projects takes less than 15 minutes *) including RabbitMQ, Solr, Git, Composer, tons of PHP modules...
  7. 7. Technological Stack VirtualBox Free open source virtualization tool Chef Automation tool for Configuration Management Vagrant “Remote control” for VirtualBox
  8. 8. What is Vagrant? • Building tool for portable work environments • Tool for distributing work environments • Written in Ruby • Open Source • Build upon well-established tools
  9. 9. Vagrant Components • Vagrant Box • Vagrantfile • Provisioners • Providers
  10. 10. Vagrant Boxes • Pre-installed base images • Used as base layer for all further provisioning • Many different boxes available online:
  11. 11. The Vagrantfile • Marks root directory of Vagrant project • Describes what Vagrant box to use • Describes settings of box (e.g. network) • Triggers the provisioning of box (using Chef)
  12. 12. Provisioners • Configures your Vagrant box by – Installing packages and software – Configuration and starting of services • Multiple provisioners available • Run once the box is booted
  13. 13. Providers • Describe in which virtualization environment to provision your machines • Multiple providers available – VirtualBox – VMWare – Amazon AWS
  14. 14. What is Chef? • Configuration Management automation tool • Written in Ruby • „Code your desired system state“ • Put system state into version control • Relies on a client / server architecture – Or use chef solo without a server
  15. 15. Chef Architecture
  16. 16. Chef Architecture
  17. 17. Using chef-solo • mount cookbooks directory into your box config.vm.synced_folder "./chef", "/var/chef" config.vm.synced_folder "./home", "/var/ vagrant-home" • run chef-solo in your box config.vm.provision :shell do |s| s.inline = "sudo chef-solo -c /var/chef/ solo.rb -j /var/vagrant-home/config.json" end
  18. 18. The solo.rb File • Define some paths: file_cache_path "/var/chef-cache" cookbook_path ["/var/chef/cookbooks”] data_bag_path "/var/chef/data_bags" role_path "/var/chef/roles"
  19. 19. The config.json File • Define cookbook runlist: {"run_list" : ["recipe[cookbook_name]"]} • Further configuration in config.json overwrites defaults in cookbooks node['key1']['key2']
  20. 20. Chef Provisioning Alternatives • Different ways for Chef provisioning – Mounting Cookbooks and use chef-solo – Copy Cookbooks into box and use chef-solo – Use Chef client in box and Chef server
  21. 21. Overview 2 Chef Cookbooks /home/vagrant/chef mounted/copied into OR taken from chef server Vagrant Box 4 uses cookbooks triggers chef 3 remote controlls 1
  22. 22. Provisioning Activity Provisioning Activity Provision Projects Configuration Management Booting Box Set up Box Chef, Git Vagrant, Chef Vagrant, VirtualBox Vagrant
  23. 23. Set Up Box 1. Install VirtualBox & Vagrant 2. Add a box vagrant box add box_name http://box_url 1. Create a first Vagrantfile mkdir vagrant cd vagrant vagrant init
  24. 24. Set up & Boot the Box 4. Use the box in your Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "box_name" end 5. Boot your machine vagrant up 6. ssh into your machine vagrant ssh
  25. 25. Versioning and Distribution • Remember: „Everything should be put into Version Control!“ • Vagrantfile can easily be put into any VCS • Distributing an environment is as easy as git clone git@github.com:my/vagrant.git cd vagrant vagrant up
  26. 26. Daily Vagrant Usage • Start the box vagrant up • Stop the box Vagrant halt • Suspend the box vagrant suspend • Resume the box vagrant resume
  27. 27. Multiple Boxes for Multiple Projects PROs - Easy to set up - Can have different systems in a box Vagrant Box Project 1 Vagrant Box Project 2 CONs - Have multiple Boxes running at the same time consumes resources Vagrant Box Project 3
  28. 28. Multiple Projects in one Box PROs - Less ressources required Vagrant Box Project 1 Project 2 Project 3 CONs - No easy way to set up - Longer provisioning time - Bigger boxes
  29. 29. Identical Copy of Server server is provisioned using Chef Client Chef Client Chef Server Chef Cookbooks mounted/copied into OR taken from chef server provisioned using same cookboks Identical Copy of Server as Vagrant Box
  30. 30. Vagrant & Chef for CI / CD • Set up the whole deployment chain locally • Use tools like Jenkins inside your boxes • Provision the projects on Jenkins with Chef
  31. 31. DevOps • Tools like Vagrant and Chef bring Developers and system operators closer together • Learn from each other • Use each other‘s tools for problem solving
  32. 32. Summary • Vagrant is a great tool for portable boxes • Chef can help you manage your configuration • „Infrastructure as Code“ • Same environment on dev and live system • DevOps brings devs and admins together

×