SlideShare une entreprise Scribd logo
1  sur  74
Télécharger pour lire hors ligne
CHEF
or how to make computers do the work for us




      Marcin Kulik, Lunar Logic Polska

             KRUG 2011/11/08
Everyday we're dealing with mechanical, repetitive tasks... we
                       can automate.
What is Chef?
Automation tool
written in Ruby
DSL
Created by Opscode
"Chef is an open source systems integration framework built
 to bring the benefits of configuration management to your
                   entire infrastructure."

"You write source code to describe how you want each part of
your infrastructure to be built, then apply those descriptions
                      to your servers."

 "The result is a fully automated infrastructure: when a new
server comes on line, the only thing you have to do is tell Chef
        what role it should play in your architecture."
Why do you need it?
Economics + Efficiency + Scalability
Terms
Node
remote server, local machine...
Role
web server, database server, ruby dev workstation...
Cookbook
mysql, ssh-access, dotfiles...
Recipe
install mysql-server, create database, add user...
Resource
file, dir, user, package, service, gem, virtual host...
Run list
list of recipes to run in order
{
    "run_list": [
      "recipe[mysql]",
      "recipe[git]",
      "recipe[ruby19]"
    ]
}
Cookbook structure
|--   config
|     |-- node.json
|     `-- solo.rb
|--   cookbooks
|     |-- book1
|     |   |-- attributes
|     |   |-- files
|     |   |-- metadata.rb
|     |   |-- recipes
|     |   |   |-- default.rb
|     |   |   `-- source.rb
|     |   `-- templates
|     |-- book2
|     |   |-- attributes
|     |   |   `-- default.rb
|     |   |-- files
|     |   |-- recipes
|     |   |   `-- default.rb
|     |   `-- templates
|     |   `-- templates
|     |       `-- default
|     |           `-- authorized_keys.erb
|     |-- book3
|     |   |-- attributes
|     |   |-- files
|     |   |   `-- default
|     |   |       `-- secret-key
|     |   |-- recipes
|     |   |   `-- default.rb

              Installation
|     |   `-- templates
|--   config
|     |-- node.json
|     `-- solo.rb
|--   cookbooks
|     |-- book1
|     |   |-- attributes
|     |   |-- files
|     |   |-- metadata.rb
|     |   |-- recipes
|     |   |   |-- default.rb
|     |   |   `-- libs.rb
|     |   `-- templates
$ gem install chef
Modes of operation
Cookbooks stored
in central repository
  (free cookbooks hosting by Opscode:
     https://manage.opscode.com/)
$ sudo chef-client
Cookbooks stored
  on the node
$ sudo chef-solo -c /path/to/cfg.rb
                 -j /path/to/node-data.json
Use cases
Configure new machine
(in the cloud with Knife)
  Amazon EC2, Engine Yard, Linode, BrightBox...
Manage config of existing
          company servers
Client demo apps (directory, vhost, god config), developers' ssh
                            keys...
Bootstrap workstation!
   rvm + ruby 1.9, git, mysql, vim/emacs...
Enough with theory!
Lunar Station
https://github.com/LunarLogicPolska/lunar-station
Lunar Station is a set of Chef cookbooks and a bash script (???)
for bootstrapping developers machines at Lunar Logic Polska.
You need ruby to run Chef
(We assume) you use RVM
  No need for system ruby for ruby devs nowadays
bootstrap.sh
detects platform (Ubuntu, Fedora, OSX)

   installs compilers and other RVM
              dependencies

  installs RVM & ruby 1.9 & chef gem

    downloads latest Lunar Station
            cookbooks

            runs chef-solo
$ curl -skL http://bit.ly/lunar-station | bash
Initializing Lunar Workstation...
>> Fedora Linux detected.
>> Checking for RVM...
>> Fetching latest version of Lunar Station cookbooks...
>> Starting chef-solo run...
[Mon, 07 Nov 2011 22:19:54 +0100] INFO: *** Chef 0.10.4 ***
[Mon, 07 Nov 2011 22:19:54 +0100] INFO: Setting the run_list to
...
Nodes
# linux-rubydev.json

{
    "run_list": [ "role[rubydev]" ]
}
# osx-rubydev.json

{
    "run_list": [ "role[osx]", "role[rubydev]" ]
}
Roles
# base.rb

run_list 'recipe[repos]',   'recipe[curl]',
         'recipe[wget]',    'recipe[git]',
         'recipe[libxml2]', 'recipe[ack]',
         'recipe[vim]',     'recipe[ctags]',
         'recipe[skype]',   'recipe[firefox]' ,
         'recipe[google-chrome]'
# rubydev.rb

run_list 'role[base]', 'recipe[mysql]'
# osx.rb

run_list "recipe[homebrew]"
Cookbooks
repos cookbook
# cookbooks/repos/recipes/default.rb

case node[:platform]
when 'fedora'
  path = "/tmp/rpmfusion-free-release-stable.noarch.rpm"

  bash "download rpmfusion free package" do
    code "wget http://download1.rpmfusion.org/.../" +
      "rpmfusion-free-release-stable.noarch.rpm -O #{path}"
    not_if { File.exist?(path) }
  end

  package "rpmfusion-free-release-stable" do
    source path
    options "--nogpgcheck"
  end
when 'ubuntu'
  ...
end
end



# cookbooks/repos/recipes/default.rb

case node[:platform]
when 'fedora'
  ...

when 'ubuntu'
  bash "enable multiverse repo" do
    code "head -n 1 /etc/apt/sources.list | " +
      "sed 's/main universe/multiverse/' " +
      ">> /etc/apt/sources.list"

    not_if "egrep '^deb.+multiverse' /etc/apt/sources.list"
  end
end
vim cookbook
# cookbooks/vim/recipes/default.rb

case node[:platform]
when "ubuntu"
  package "vim"
  package "vim-gnome"

when "fedora"
  package "vim-enhanced"
  package "vim-X11"

when 'mac_os_x'
  package "macvim"
end
skype cookbook
# cookbooks/skype/recipes/default.rb

case node[:platform]
when 'ubuntu'
  include_recipe 'init::ubuntu' # for partner repo
  package 'skype'

when 'mac_os_x'
  dmg_package "Skype" do
    source "http://www.skype.com/go/getskype-macosx.dmg"
    action :install
  end
when 'fedora'
  ...
end
Lunar Kitchen
Source of LLP servers configuration data and a set of Chef
                       cookbooks
chef-solo invoked on
  remote machines
    no chef server
Each server we configure has its corresponding node
configuration file in nodes/ directory of kitchen project that
         specifies run_list and few other settings
# nodes/deneb.json

{
    "run_list": [ "recipe[ssh_access]" ],

    "ssh_access": [ "marcin.kulik", "anna.lesniak", ...],
    "opened_ports": {
       "tcp": [80, 443, 22, 8080],
       "udp": []
    },
    ...
How do we run chef-solo
  on remote machine?
Capistrano!
# See the list of configured servers:
$ cap -T


# Make the changes happen on the server:

$ cap configure:deneb
How does Capfile look like?
set :user, 'chef'
NODE_LIST = Dir["nodes/*.json"].map do |nodefile|
  File.basename(nodefile, '.json')
end
NODE_LIST.each do |node|
  role node.to_sym, node
end
NODE_CONFIG = <<-EOS
  file_cache_path '/tmp/chef-solo'
  cookbook_path '/tmp/chef-solo/cookbooks'
  role_path '/tmp/chef-solo/roles'
EOS
...
...
namespace :configure do
  NODE_LIST.each do |node|
    desc "Configure #{node}"
    task node.to_sym, :roles => node.to_sym do
      run "if [ ! -e /tmp/chef-solo ]; then mkdir /tmp/chef-sol
      upload("cookbooks", "/tmp/chef-solo/", :via => :scp, :rec
      upload("roles", "/tmp/chef-solo/", :via => :scp, :recursi
      upload("nodes/#{node}.json", "/tmp/chef-solo/node.json",
      put(NODE_CONFIG, "/tmp/chef-solo/solo.rb")
      run "rvmsudo chef-solo " +
                   "-c /tmp/chef-solo/solo.rb " +
                   "-j /tmp/chef-solo/node.json"
    end
  end
end
SSH access
├──   Capfile
├──   config
├──   cookbooks
├──   nodes
├──   README.md
├──   roles
└──   ssh_keys
      ├── anna.lesniak
      ├── artur.bilski
      ├── ...
      └── marcin.kulik
# cookbooks/access/recipes/default.rb

username = 'dev'

ssh_keys = node[:ssh_access].map do |f|
  File.read("/tmp/chef-solo/ssh_keys/#{f}")
end

template "/home/#{username}/.ssh/authorized_keys" do
  source "authorized_keys.erb"
  owner username
  group 'users'
  mode "0600"
  variables :ssh_keys => ssh_keys
end
# cookbooks/access/templates/authorized_keys.erb

# Generated by Chef, do not edit!

<%= @ssh_keys.join("n") %>
Tips
Learn step by step
EC2 + Chef + Knife + Opscode... = Fuuuuuuuuuuuuuuuuuuuuu
Start with chef-solo
Run on local machine
    Easy to troubleshoot problems
Use Vagrant
                 http://vagrantup.com/


Great for testing cookbooks - doesn't pollute your system
Q?
Thanks!
marcin.kulik@llp.pl | @sickill | https://github.com/sickill

Contenu connexe

Tendances

Tendances (20)

Chef
ChefChef
Chef
 
A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of Ansible
 
docker build with Ansible
docker build with Ansibledocker build with Ansible
docker build with Ansible
 
Chef
ChefChef
Chef
 
Configuration management and orchestration with Salt
Configuration management and orchestration with SaltConfiguration management and orchestration with Salt
Configuration management and orchestration with Salt
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / Quickstart
 
Automated infrastructure is on the menu
Automated infrastructure is on the menuAutomated infrastructure is on the menu
Automated infrastructure is on the menu
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done right
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricks
 
Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
Introducing Ansible
Introducing AnsibleIntroducing Ansible
Introducing Ansible
 
Chef
ChefChef
Chef
 
Herd your chickens: Ansible for DB2 configuration management
Herd your chickens: Ansible for DB2 configuration managementHerd your chickens: Ansible for DB2 configuration management
Herd your chickens: Ansible for DB2 configuration management
 
V2 and beyond
V2 and beyondV2 and beyond
V2 and beyond
 

Similaire à Chef or how to make computers do the work for us

Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
Simon McCartney
 
Practical introduction to dev ops with chef
Practical introduction to dev ops with chefPractical introduction to dev ops with chef
Practical introduction to dev ops with chef
LeanDog
 

Similaire à Chef or how to make computers do the work for us (20)

Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Cook Infrastructure with chef -- Justeat.IN
Cook Infrastructure with chef  -- Justeat.INCook Infrastructure with chef  -- Justeat.IN
Cook Infrastructure with chef -- Justeat.IN
 
[MDBCI] Mariadb continuous integration tool
[MDBCI] Mariadb continuous integration tool[MDBCI] Mariadb continuous integration tool
[MDBCI] Mariadb continuous integration tool
 
Chef introduction
Chef introductionChef introduction
Chef introduction
 
Chef training - Day2
Chef training - Day2Chef training - Day2
Chef training - Day2
 
Configuration management with Chef
Configuration management with ChefConfiguration management with Chef
Configuration management with Chef
 
Chef solo the beginning
Chef solo the beginning Chef solo the beginning
Chef solo the beginning
 
Introduction to chef framework
Introduction to chef frameworkIntroduction to chef framework
Introduction to chef framework
 
Kickstarter - Chef Opswork
Kickstarter - Chef OpsworkKickstarter - Chef Opswork
Kickstarter - Chef Opswork
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Cooking 5 Star Infrastructure with Chef
Cooking 5 Star Infrastructure with ChefCooking 5 Star Infrastructure with Chef
Cooking 5 Star Infrastructure with Chef
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
 
Deploying OpenStack with Chef
Deploying OpenStack with ChefDeploying OpenStack with Chef
Deploying OpenStack with Chef
 
AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013
AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013
AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013
 
Linecook - A Chef Alternative
Linecook - A Chef AlternativeLinecook - A Chef Alternative
Linecook - A Chef Alternative
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and Packer
 
Practical introduction to dev ops with chef
Practical introduction to dev ops with chefPractical introduction to dev ops with chef
Practical introduction to dev ops with chef
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
DevOps hackathon Session 2: Basics of Chef
DevOps hackathon Session 2: Basics of ChefDevOps hackathon Session 2: Basics of Chef
DevOps hackathon Session 2: Basics of Chef
 

Dernier

Dernier (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Chef or how to make computers do the work for us