Alexey Vasiliev

  • 6+ years experience
    • Linux and Databases administrator
    • Web and Mobile developer (Ruby, Java, JavaScript, Objective-C, C/C++)
  • Open-Source developer
    • 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 Solo

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

  gem install knife-solo
        

Main commands:

  • kitchen
  • prepare
  • cook
  • wash_up
Chef

Kitchen

Chef Solo

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 Solo

  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 Solo

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

Librarian

Chef Solo

  $ 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'
      

Recipe

Chef Solo

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

Recipe definitions

Chef Solo

        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 Solo

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

or

        include_recipe "nginx::source"
      

Simple example of own recipe

Chef Solo

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

Chef Server

chef

Requirements:

  • Ruby (of cource!)
  • Merb
  • CouchDB
  • Java
  • RabbitMQ

Chef Server

chef

Vagrant

Chef

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

Chef-Solo + Caphub = <3

Chef Solo

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 for such task!

<Thank You!>

Contact information