Alexey Vasiliev

  • 6+ years experience
    • Linux and Databases administrator
    • Web and Mobile developer (Ruby, Java, JavaScript, Objective-C, C/C++)
  • Open-Source developer
    • WebP-ffi
    • MongodbLogger for Rails
    • Piro - Chrome extension for PivotalTracker
    • SMTRails and SHTRails (shared templates for rails)
    • SkypeKit for Ruby
me

Chef

Chef

Chef

Chef is an open-source systems integration framework built specifically for automating the cloud.

Why Chef?

  • Efficiency
  • Scalability
  • Reusing
  • Save money
  • Documentation
Chef

Why Chef?

Chef
Chef is like unit tests for your servers.
Ezra Zygmuntowicz

Main idea of Chef: Idempotence

Chef

Idempotence

It can safely be run multiple times. Once you develop your configuration, your machines will apply the configuration and Chef will only make any changes to the system if the system state does not match the configured state.

What doesn't Chef do?

  • "Magically" configure your server
  • Blindly reuse cookbooks and recipes
  • Monitor your servers or softwares
  • Undoing concept
Chef

Chef Types

  • Chef Solo
  • Chef Server
  • Hosted Chef (Chef Server by Opscode)
Chef

Terminology

Chef

  • Node
  • Chef Server
  • Chef Client
  • recipe
  • cookbook
  • role
  • run list
  • attribute

Knife

Chef

Knife is a powerful command-line interface (CLI) that comes with Chef.

Example for Chef Solo:

  gem install knife-solo
        

Main commands:

  • kitchen
  • prepare
  • cook
  • wash_up
Chef

Kitchen

Chef

Kitchen is a place where you build and store recipes. And cook!

  knife kitchen mychefrepo
          

The kitchen command simply takes a name of the directory to store the kitchen structure.




      mykitchen/
      ├── cookbooks
      ├── data_bags
      ├── nodes
      ├── roles
      ├── site-cookbooks
      └── solo.rb
          

Prepare & Cook

Chef

  knife prepare ubuntu@10.0.0.201
      
  knife bootstrap --template-file bootstrap.centos.erb -u root 10.0.0.201
  echo '{"run_list":[]}' > nodes/10.0.0.201.json
      
  knife cook ubuntu@10.0.0.201
      

That's it!

Librarian

Chef

  gem install librarian
  librarian-chef init
  librarian-chef install
          
librarian

Librarian

Chef

  $ cat Cheffile
  #!/usr/bin/env ruby
  site 'http://community.opscode.com/api/v1'

  cookbook 'nginx',
    :git => 'git://github.com/opscode-cookbooks/nginx.git'
  cookbook 'rvm'
  cookbook 'ruby_build'
  cookbook 'rbenv',
    :git => 'https://github.com/fnichol/chef-rbenv'
  cookbook 'postgresql',
    :git => 'git://github.com/opscode-cookbooks/postgresql.git'
      

Berkshelf

Chef

  gem install berkshelf
  berks install
          
Berkshelf

Berkshelf

Chef

  $ cat Berksfile
  #!/usr/bin/env ruby
  site :opscode

  cookbook 'mysql'
  cookbook 'nginx', '~> 0.101.5'
      

Recipe

Chef

    ├── CHANGELOG.md
    ├── CONTRIBUTING
    ├── Gemfile
    ├── LICENSE
    ├── README.md
    ├── attributes
    ├── definitions
    ├── files
    ├── metadata.rb
    ├── recipes
    ├── templates
    └── test
      

Recipe definitions

Chef

        template "#{node[:nginx][:dir]}/sites-available/#{node[:app][:name]}.conf" do
          source "nginx.conf.erb"
          mode "0644"
        end
        nginx_site "#{node[:app][:name]}.conf"
      
        $ cat nginx.conf.erb
        upstream prod_unicorn {
          server unix:<%= node[:app][:web_dir] %>/shared/tmp/sockets/unicorn.sock fail_timeout=0;
        }
        server {
            listen 80 default;
            ...
      

Recipe execution

Chef

        "run_list": [
          "nginx[source]"
        ]
      

or

        include_recipe "nginx::source"
      

Simple example of own recipe

Chef

        ├── recipes
        │   └── default.rb
        └── templates
            └── default
                ├── database.yml.erb
                ├── nginx.conf.erb
                └── unicorn.rb.erb
      

Chef Server

Chef Server

chef

Vagrant

Chef

  • Download VirtualBox
  • Download OS image
  • Initialize virtual mashine
  • Test your kitchen!
vagrant

Chef-Solo (or Server) + Caphub = <3

Chef

Summary

  • All configs and steps to setup your cloud in one place - in your git repository
  • Easy to maintain and update your servers
  • Easy to create the same copy of instances
  • Ruby language - perfect choice as DSL for cookbooks!

Summary

Chef

<Thank You!>

Contact information