CHEF, VAGRANT
AND FRIENDS
AUTOMATING YOUR ENVIRONMENTS
@benmcrae
• Software engineer
• CompareTheMarket.com
• Travelling & listening to music
• Coffee / real ale drinker
YOU?
MASTER CHEFS
SOFTWARE!
CONFIGURATION
MANAGEMENT
Chef can automate how you
configure, deploy and scale
your servers and applications.
GETTING
STARTED
Installing Chef 11
!
Chef Omnibus (Linux, OS X, Windows)
Chef DK (April 2014, v0.1.0) (Bundled software)
Gem (Ruby 1.9.3 r...
Chef CLI tools
ohai (node attributes)
chef-apply (execute a single recipe from the command line)
chef-solo (execute run li...
INFRASTRUCTURE
AS CODE
Resources
Resources represent a piece of the system and its
desired state. Some resources available:!
• Directories
• User...
Resource Syntax
A resource is a Ruby block with four components:
• A type
• A name
• One (or more) attributes (with values...
Recipe
Recipes are what you write to install and configure
things on your machine.!
• Authored using a Ruby DSL
• Made from...
Recipe DSL
A Ruby DSL, with specific methods to write
chef recipes and resource blocks.
Common Ruby syntax can be used with...
FIRST RECIPE
Ingredients
• Using chef-apply and a single recipe
• Create a new developer user on the system
• Install Git using the OS ...
stage-1
https://github.com/benmcrae/ddd-chef-examples/tree/master/stage-1
Chef Run
• Recipe loaded
• Resources are arranged in an ordered queue
• Each resource is mapped to a Provider!
• The node ...
Providers
Providers define steps that are needed to
bring a piece of the system from its current
state into the desired sta...
Idempotent
A recipe can run multiple times on the
same system and the results will always be
identical.
RETROSPECTIVE
Outcomes
• Poor single responsibility
• Use better suited resources e.g. template / file
• Fixed values could be swapped fo...
Next Steps
1. Create cookbook from existing recipe
2. Refactor outcomes from retrospective
FIRST COOKBOOK
Cookbook
A cookbook defines a scenario, such as
everything needed to install and configure
Apache and the resources that sup...
Cookbook Folders
• attributes - attribute files, loaded in alphabetical order!
• files - stored files for file and directory r...
Cookbook Generators
• knife cookbook create ‘cookbook name’
• berks cookbook ‘cookbook name’
Metadata File
• The metadata.rb sits in the cookbook root directory
• Defines cookbook name, version, and description
• Can...
REFACTOR
Template Resource
• Uses ERB (Embedded Ruby) files
• Supports variables and hashes in templates
• Multi nested folders desi...
Node Object
• Attributes - An attribute is a specific piece of data
about the node!
• Run list - A run-list is an ordered l...
Attributes
!
• Attributes can be defined by the node, recipes,
cookbooks, roles and environments!
• Node information. i.e. ...
Overriding Attributes
Ohai
Ohai is a CLI tool that is used to detect attributes on a node!
• Platform details
• Network usage
• Memory usage
• P...
Run List
• A run-list defines all of the configuration settings
that are necessary for a node to converge
• An ordered list ...
chef-solo
• chef-solo allows using cookbooks on nodes without
using Chef server
• Cookbooks & dependencies must be on the ...
stage-2
https://github.com/benmcrae/ddd-chef-examples/tree/master/stage-2
Chef Run
• Builds node object!
• Expands run-list
• Compiles Resources in an ordered queue
• Each resource is mapped to a ...
RETROSPECTIVE
Outcomes
• A single cookbook to manage our developer user
• A cookbook that can be used with both chef-solo
and chef-clien...
Next Steps
• Introduce community cookbooks and Berkshelf
• Install Ruby 2.1.2, using Berkshelf
COMMUNITY
COOKBOOKS
Community Cookbooks
• An online Open Source cookbook repository,
maintained and used by the chef community.
• Trusted cook...
Berkshelf
• The cookbook dependency manager
• gem install berkshelf
• Used to maintain cookbooks on your Chef Server
• Wri...
Berksfile
• Lives in the root directory of the Cookbook
• Lists each cookbook name, and version (optional)
which your cookb...
stage-3
https://github.com/benmcrae/ddd-chef-examples/tree/master/stage-3
RETROSPECTIVE
Outcomes
• Implemented a community cookbook with the aid of
Berkshelf.
• Applied our knowledge of attributes to other
cook...
Next Steps
• Provision the node automatically with chef-solo and
Vagrant.
• Create a new recipe to git clone our ruby app ...
• Create and configure lightweight, reproducible,
and portable development environments.
• Vagrant stands on the shoulders ...
Commands
• vagrant init hashicorp/precise32
• vagrant up
• vagrant provision
• vagrant halt
• vagrant destroy
Vagrant Provision
• Move the run list and attributes into the Vagrantfile
• Vagrant will run chef-solo on VM start, or by r...
Git Resource
• Manage source control resources that exist in a git
repository
• Functionality for revision and branching c...
stage-4
https://github.com/benmcrae/ddd-chef-examples/tree/master/stage-4
RETROSPECTIVE
Outcomes
• Used Vagrant to run chef-solo and setup our node
• Established our cookbook development workflow
• Finished cook...
VAGRANT CONT.
More Features
• Full support for both Linux and Windows guest’s
• Mount directories using either NFS, SMB or Rsync
• Multi...
Vagrant Cloud
• Share a link to your web server to a teammate
across the country
• Community collection of fully baked box...
Share / Connect
• Share SSH access to other vagrant users
• Share the whole machine as a local entity to other
vagrant use...
Vagrant Plugins
• vagrant plugin install <plugin_name>
• vagrant-sahara (operate in a sandbox environment)
• vagrant-proxy...
Chef Reading
• Test-Driven Infrastructure with Chef, 2nd Edition

- Steven Nelson-Smith
• Chef Infrastructure Automation C...
Vagrant Reading
• Vagrant: Up and Running - Mitchell Hashimoto
• http://docs.vagrantup.com/
• http://www.vagrantup.com/blo...
THANK YOU
Chef, Vagrant and Friends
Chef, Vagrant and Friends
Chef, Vagrant and Friends
Chef, Vagrant and Friends
Chef, Vagrant and Friends
Chef, Vagrant and Friends
Chef, Vagrant and Friends
Chef, Vagrant and Friends
Chef, Vagrant and Friends
Chef, Vagrant and Friends
Upcoming SlideShare
Loading in …5
×

Chef, Vagrant and Friends

574 views

Published on

An introduction to using Chef and Vagrant for entry level users.

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
574
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Chef, Vagrant and Friends

  1. 1. CHEF, VAGRANT AND FRIENDS AUTOMATING YOUR ENVIRONMENTS
  2. 2. @benmcrae • Software engineer • CompareTheMarket.com • Travelling & listening to music • Coffee / real ale drinker
  3. 3. YOU?
  4. 4. MASTER CHEFS
  5. 5. SOFTWARE! CONFIGURATION MANAGEMENT
  6. 6. Chef can automate how you configure, deploy and scale your servers and applications.
  7. 7. GETTING STARTED
  8. 8. Installing Chef 11 ! Chef Omnibus (Linux, OS X, Windows) Chef DK (April 2014, v0.1.0) (Bundled software) Gem (Ruby 1.9.3 recommended)
  9. 9. Chef CLI tools ohai (node attributes) chef-apply (execute a single recipe from the command line) chef-solo (execute run lists and cookbooks on a node) chef-client (retrieves & executes run lists & cookbooks on nodes) knife (interact with chef server)
  10. 10. INFRASTRUCTURE AS CODE
  11. 11. Resources Resources represent a piece of the system and its desired state. Some resources available:! • Directories • Users • Groups • Services • Packages
  12. 12. Resource Syntax A resource is a Ruby block with four components: • A type • A name • One (or more) attributes (with values) • One (or more) actions
  13. 13. Recipe Recipes are what you write to install and configure things on your machine.! • Authored using a Ruby DSL • Made from multiple resources • Can include other recipes • Single responsibility in purpose • Belongs to a Cookbook
  14. 14. Recipe DSL A Ruby DSL, with specific methods to write chef recipes and resource blocks. Common Ruby syntax can be used with the Recipe DSL methods. if / case statements…
  15. 15. FIRST RECIPE
  16. 16. Ingredients • Using chef-apply and a single recipe • Create a new developer user on the system • Install Git using the OS package manager • Create a .gitconfig file for the developer user
  17. 17. stage-1 https://github.com/benmcrae/ddd-chef-examples/tree/master/stage-1
  18. 18. Chef Run • Recipe loaded • Resources are arranged in an ordered queue • Each resource is mapped to a Provider! • The node Converges by executing each provider
  19. 19. Providers Providers define steps that are needed to bring a piece of the system from its current state into the desired state.
  20. 20. Idempotent A recipe can run multiple times on the same system and the results will always be identical.
  21. 21. RETROSPECTIVE
  22. 22. Outcomes • Poor single responsibility • Use better suited resources e.g. template / file • Fixed values could be swapped for attributes
  23. 23. Next Steps 1. Create cookbook from existing recipe 2. Refactor outcomes from retrospective
  24. 24. FIRST COOKBOOK
  25. 25. Cookbook A cookbook defines a scenario, such as everything needed to install and configure Apache and the resources that support it.
  26. 26. Cookbook Folders • attributes - attribute files, loaded in alphabetical order! • files - stored files for file and directory resources! • libraries - arbitrary ruby libraries, used in recipes! • providers - custom providers (LWRP)! • recipes - recipe files! • resources - custom resources (LWRP)! • templates - erb files for the template resource
  27. 27. Cookbook Generators • knife cookbook create ‘cookbook name’ • berks cookbook ‘cookbook name’
  28. 28. Metadata File • The metadata.rb sits in the cookbook root directory • Defines cookbook name, version, and description • Can declare dependencies on other cookbooks • List supported operating systems
  29. 29. REFACTOR
  30. 30. Template Resource • Uses ERB (Embedded Ruby) files • Supports variables and hashes in templates • Multi nested folders designed to support distributing files across platforms • Best practice: set variables using attributes
  31. 31. Node Object • Attributes - An attribute is a specific piece of data about the node! • Run list - A run-list is an ordered list of recipes and/or roles that are run in an exact order
  32. 32. Attributes ! • Attributes can be defined by the node, recipes, cookbooks, roles and environments! • Node information. i.e. IP / MAC addresses, OS info • Recipe information. i.e. directory paths, users, application data
  33. 33. Overriding Attributes
  34. 34. Ohai Ohai is a CLI tool that is used to detect attributes on a node! • Platform details • Network usage • Memory usage • Processor usage
  35. 35. Run List • A run-list defines all of the configuration settings that are necessary for a node to converge • An ordered list of roles and/or recipes that are run in an exact order
  36. 36. chef-solo • chef-solo allows using cookbooks on nodes without using Chef server • Cookbooks & dependencies must be on the node • Limited in functionality compared to chef-server • Requires configuration; run-list and attributes
  37. 37. stage-2 https://github.com/benmcrae/ddd-chef-examples/tree/master/stage-2
  38. 38. Chef Run • Builds node object! • Expands run-list • Compiles Resources in an ordered queue • Each resource is mapped to a Provider! • The node Converges by executing each provider
  39. 39. RETROSPECTIVE
  40. 40. Outcomes • A single cookbook to manage our developer user • A cookbook that can be used with both chef-solo and chef-client (Chef Server)
  41. 41. Next Steps • Introduce community cookbooks and Berkshelf • Install Ruby 2.1.2, using Berkshelf
  42. 42. COMMUNITY COOKBOOKS
  43. 43. Community Cookbooks • An online Open Source cookbook repository, maintained and used by the chef community. • Trusted cookbooks can be downloaded from - http://community.opscode.com • Cookbook dependencies are not automatically downloaded. This must be done by looking through the cookbook metadata file, and manually downloading listed cookbooks.
  44. 44. Berkshelf • The cookbook dependency manager • gem install berkshelf • Used to maintain cookbooks on your Chef Server • Written by Jamie Windsor, and Seth Vargo
  45. 45. Berksfile • Lives in the root directory of the Cookbook • Lists each cookbook name, and version (optional) which your cookbook depends on • Ability to read cookbook dependencies from metadata.rb file • Traverses over other cookbook dependencies
  46. 46. stage-3 https://github.com/benmcrae/ddd-chef-examples/tree/master/stage-3
  47. 47. RETROSPECTIVE
  48. 48. Outcomes • Implemented a community cookbook with the aid of Berkshelf. • Applied our knowledge of attributes to other cookbooks.
  49. 49. Next Steps • Provision the node automatically with chef-solo and Vagrant. • Create a new recipe to git clone our ruby app into the developer home directory.
  50. 50. • Create and configure lightweight, reproducible, and portable development environments. • Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. • Provision machines with, shell scripts, Chef, or Puppet.
  51. 51. Commands • vagrant init hashicorp/precise32 • vagrant up • vagrant provision • vagrant halt • vagrant destroy
  52. 52. Vagrant Provision • Move the run list and attributes into the Vagrantfile • Vagrant will run chef-solo on VM start, or by running the provision command
  53. 53. Git Resource • Manage source control resources that exist in a git repository • Functionality for revision and branching control • Offers both export and syncing abilities
  54. 54. stage-4 https://github.com/benmcrae/ddd-chef-examples/tree/master/stage-4
  55. 55. RETROSPECTIVE
  56. 56. Outcomes • Used Vagrant to run chef-solo and setup our node • Established our cookbook development workflow • Finished cookbook
  57. 57. VAGRANT CONT.
  58. 58. More Features • Full support for both Linux and Windows guest’s • Mount directories using either NFS, SMB or Rsync • Multi machine environments • Network support - port forwarding, private networks
  59. 59. Vagrant Cloud • Share a link to your web server to a teammate across the country • Community collection of fully baked box images • Distribute versionable private environments to your team
  60. 60. Share / Connect • Share SSH access to other vagrant users • Share the whole machine as a local entity to other vagrant users
  61. 61. Vagrant Plugins • vagrant plugin install <plugin_name> • vagrant-sahara (operate in a sandbox environment) • vagrant-proxy (define http and https proxies)
  62. 62. Chef Reading • Test-Driven Infrastructure with Chef, 2nd Edition
 - Steven Nelson-Smith • Chef Infrastructure Automation Cookbook 
 - Matthias Marschall • Learning Chef (Released Sep 2014)
 - Seth Vargo, Mischa Taylor • https://learnchef.opscode.com/
  63. 63. Vagrant Reading • Vagrant: Up and Running - Mitchell Hashimoto • http://docs.vagrantup.com/ • http://www.vagrantup.com/blog.html
  64. 64. THANK YOU

×