Transcript
Page 1: Vagrant and Chef on FOSSASIA 2014

Reproducible and Portable Work

Environments with Vagrant and Chef

Page 2: Vagrant and Chef on FOSSASIA 2014

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

Page 3: Vagrant and Chef on FOSSASIA 2014

I am NO

Vagrant /

Chef

Guru!!!

Page 4: Vagrant and Chef on FOSSASIA 2014

Outline

• Motivation

• Introducing Vagrant & Chef

• Vagrant „Hands-On“

• Advanced usage

Page 5: Vagrant and Chef on FOSSASIA 2014

Motivation

Page 6: Vagrant and Chef on FOSSASIA 2014

Motivation

• Internal project

• Estimated development time ~2

years

• Approx. 15 developers

• 2-day sprints, every second week

• 4 developers per sprint

Page 7: Vagrant and Chef on FOSSASIA 2014

MotivationObservations

• 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

Page 8: Vagrant and Chef on FOSSASIA 2014

Solution: Vagrant BoxesProvisioning 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...

Page 9: Vagrant and Chef on FOSSASIA 2014

Technological StackVirtualBoxFree open source virtualization tool

ChefAutomation tool for Configuration Management

Vagrant“Remote control” for VirtualBox

Page 10: Vagrant and Chef on FOSSASIA 2014

Introducing

Vagrant

Page 11: Vagrant and Chef on FOSSASIA 2014

What is Vagrant?• Building tool for portable work

environments

• Tool for distributing work

environments

• Written in Ruby

• Open Source

• Build upon well-established tools

Page 12: Vagrant and Chef on FOSSASIA 2014

Vagrant Components

• Vagrant Box

• Vagrantfile

• Provisioners

• Providers

Page 13: Vagrant and Chef on FOSSASIA 2014

Vagrant Boxes

• Pre-installed base images

• Used as base layer for all further

provisioning

• Many different boxes available

online:

Page 14: Vagrant and Chef on FOSSASIA 2014

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)

Page 15: Vagrant and Chef on FOSSASIA 2014

Provisioners

• Configures your Vagrant box by

– Installing packages and software

– Configuration and starting of services

• Multiple provisioners available

• Run once the box is booted

Page 16: Vagrant and Chef on FOSSASIA 2014

Providers

• Describe in which virtualization

environment to provision your machines

• Multiple providers available

– VirtualBox

– VMWare

– Amazon AWS

Page 17: Vagrant and Chef on FOSSASIA 2014

Introducing

Chef

Page 18: Vagrant and Chef on FOSSASIA 2014

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

Page 19: Vagrant and Chef on FOSSASIA 2014

Chef Architecture

Page 20: Vagrant and Chef on FOSSASIA 2014

Chef Architecture

Page 21: Vagrant and Chef on FOSSASIA 2014

Provisionin

g with Chef

Page 22: Vagrant and Chef on FOSSASIA 2014

Using chef-solo

• mount cookbooks directory into your

box

• run chef-solo in your box

config.vm.synced_folder "./chef", "/var/chef"config.vm.synced_folder "./home", "/var/\ vagrant-home"

config.vm.provision :shell do |s| s.inline = "sudo chef-solo -c /var/chef/\ solo.rb -j /var/vagrant-home/config.json"end

Page 23: Vagrant and Chef on FOSSASIA 2014

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"

Page 24: Vagrant and Chef on FOSSASIA 2014

The config.json File

• Define cookbook runlist:

• Further configuration in config.json

overwrites defaults in cookbooks

{"run_list" : ["recipe[cookbook_name]"]}

node['key1']['key2']

Page 25: Vagrant and Chef on FOSSASIA 2014

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

Page 26: Vagrant and Chef on FOSSASIA 2014

Overview

1

2

3

4

Page 27: Vagrant and Chef on FOSSASIA 2014

“Hands-on”

Page 28: Vagrant and Chef on FOSSASIA 2014

Provisioning ActivityP

rovis

ion

ing

A

cti

vit

y

Set up Box

Booting Box

Configuration Management

Provision Projects

Vagrant

Vagrant,VirtualBox

Vagrant,Chef

Chef,Git

Page 29: Vagrant and Chef on FOSSASIA 2014

Set Up Box

1. Install VirtualBox & Vagrant

2. Add a box

3. Create a first Vagrantfilemkdir vagrantcd vagrantvagrant init

vagrant box add box_name http://box_url

Page 30: Vagrant and Chef on FOSSASIA 2014

Set up & Boot the Box

4. Use the box in your Vagrantfile

5. Boot your machine

6. ssh into your machine

Vagrant.configure("2") do |config|config.vm.box = "box_name"

end

vagrant up

vagrant ssh

Page 31: Vagrant and Chef on FOSSASIA 2014

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 asgit clone [email protected]:my/vagrant.gitcd vagrantvagrant up

Page 32: Vagrant and Chef on FOSSASIA 2014

Daily Vagrant Usage

• Start the box

• Stop the box

• Suspend the box

• Resume the box

vagrant up

Vagrant halt

vagrant suspend

vagrant resume

Page 33: Vagrant and Chef on FOSSASIA 2014

Advanced

Usage

Page 34: Vagrant and Chef on FOSSASIA 2014

PROs- Easy to set up- Can have different systems

in a box

CONs- Have multiple Boxes running

at the same time consumes resources

Multiple Boxes for Multiple Projects

Page 35: Vagrant and Chef on FOSSASIA 2014

Multiple Projects in one Box

PROs- Less ressources required

CONs- No easy way to set up- Longer provisioning time- Bigger boxes

Page 36: Vagrant and Chef on FOSSASIA 2014

Identical Copy of Server

Page 37: Vagrant and Chef on FOSSASIA 2014

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

Page 38: Vagrant and Chef on FOSSASIA 2014

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

Page 39: Vagrant and Chef on FOSSASIA 2014
Page 40: Vagrant and Chef on FOSSASIA 2014
Page 41: Vagrant and Chef on FOSSASIA 2014

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


Top Related