$30 off During Our Annual Pro Sale. View Details »

Introduction to Chef - FOSDEM 2013

Nathen Harvey
February 02, 2013

Introduction to Chef - FOSDEM 2013

Quick introduction to Chef given at FOSDEM 2013. The code for this presentation can be found at https://github.com/nathenharvey/wordpress-quick-start

Nathen Harvey

February 02, 2013
Tweet

More Decks by Nathen Harvey

Other Decks in Technology

Transcript

  1. Introduction to Chef Nathen Harvey @nathenharvey FOSDEM 2013 github.com/nathenharvey/wordpress-quick-start

  2. Hello! • Technical Community Manager, Opscode • Co-host of the

    Food Fight Show Podcast
  3. The Opscode Story Opscode is… • A provider of infrastructure

    automation. • Helping hundreds of companies develop fully automated infrastructure behind the firewall and in the cloud. • Supported by a community of thousands of users. • A member of the DevOps movement. • Committed to driving next-generation infrastructure development.
  4. What is Chef? Recipes and Cookbooks that describe Infrastructure as

    Code. Chef enables people to easily build & manage complex & dynamic applications at massive scale • New model for describing infrastructure that promotes reuse • Programmatically provision and configure • Reconstruct business from code repository, data backup, and bare metal resources Chef is an automation platform for developers & systems engineers to continuously define, build, and manage infrastructure. CHEF USES: “ ”
  5. http://www.flickr.com/photos/francoforeshock/5716969942/ Configuration Desperation

  6. Our Objective Load Balancer Database Web Server Web Server

  7. Building Wordpress • Identify the resources

  8. Chef Resources • Have a type. • Have a name.

    • Have parameters. • Take action to put the resource in the declared state. • Can send notifications to other resources. package "haproxy" do action :install end template "/etc/haproxy/haproxy.cfg" do source "haproxy.cfg.erb" owner "root" group "root" mode 0644 notifies :restart, "service[haproxy]" end service "haproxy" do supports :restart => true action [:enable, :start] end
  9. Building Wordpress • Identify the resources • Write recipes •

    Package recipes in cookbooks
  10. Recipes and Cookbooks • Recipes are collections of Resources •

    Cookbooks contain recipes, templates, files, custom resources, etc • Code re-use and modularity http://www.flickr.com/photos/shutterhacks/4474421855/
  11. © Opscode, 2011 – Confidential – DO NOT DISTRIBUTE Chef

    Provides a Model for Reuse That Works 11 700+ Cookbooks “Yesterday we started open sourcing some of our Opscode Chef work created at bestbuy.com; bit.ly/ yDV9Hl #Splunk #opschef #expectmor”
  12. Building Wordpress • Identify the resources • Write recipes •

    Package recipes in cookbooks • Bundle the recipes into roles
  13. Role name: load-balancer run_list: role[base] recipe[fosdem-loadbalancer]

  14. Building Wordpress • Identify the resources • Write recipes •

    Package recipes in cookbooks • Bundle the recipes into roles • Apply the roles to nodes
  15. Run Lists Server Server Server Server chef-server API chef-client “role[base]”,

    “role[load-balancer]” node apt default.rb build- essential default.rb loadbalancer default.rb
  16. Building Wordpress • Identify the resources • Write recipes •

    Package recipes in cookbooks • Bundle the recipes into roles • Apply the roles to nodes • Provision Infrastructure
  17. Provision with Knife EC2 $ knife ec2 server create -I

    ami-3d4ff254 -f m1.medium -r 'role[database-server]' $ knife ec2 server create -I ami-3d4ff254 -f m1.medium -r 'role[application-server]' $ knife ec2 server create -I ami-3d4ff254 -f m1.medium -r 'role[application-server]' $ knife ec2 server create -I ami-3d4ff254 -f m1.medium -r 'role[load-balancer]'
  18. Chef

  19. Search • Chef includes a searchable database of information about

    your infrastructure
  20. Search • Use Search in recipes • db_node = search(:node,"role:database-server")

    • pool_members = search("node", "role:#{node['haproxy']['app_server_role']} AND chef_environment:#{node.chef_environment}") || [] • Use Search with knife • $ knife search node role:database-server
  21. Ruby, when you need it ruby_block "configure-replica-set" do block do

    require "rubygems" require "mongo" if node['mongodb']['replicaset'].nil? Chef::Log.warn("recipe[mongodb::replset] applied to node without mongodb.replicaset attribute, skipping") next end # Retry 5 times, as we believe that there should # be a mongod accepting connections on localhost conn = nil 10.times do |try| begin conn = Mongo::Connection.new( "localhost", node['mongodb']['port'], :slave_ok => true, :connect_timeout => 5) rescue delay = 2 ** (try + 1) Chef::Log.info("Failed to connect to mongodb, sleeping #{delay}, try #{try}/10") sleep(delay) end end end
  22. But wait, there’s more! • Encrypted Data Bags • Environments

    • Lightweight Resources and Providers • Exception and Report Handlers
  23. Thank You! Nathen Harvey @nathenharvey FOSDEM 2013