Customizing Chef for Fun and Profit
Upcoming SlideShare
Loading in...5
×
 

Customizing Chef for Fun and Profit

on

  • 4,687 views

Chefconf 2014

Chefconf 2014

Statistics

Views

Total Views
4,687
Views on SlideShare
4,645
Embed Views
42

Actions

Likes
14
Downloads
48
Comments
0

5 Embeds 42

https://twitter.com 18
http://www.google.com 14
http://www.slideee.com 6
https://mail.google.com 3
https://www.linkedin.com 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Customizing Chef for Fun and Profit Customizing Chef for Fun and Profit Presentation Transcript

    • Customizing Chef For Fun and Profit
    • @jonlives Jon Cowie Sr Operations Engineer
    • @jonlives
    • @jonlives
    • @jonlives Beginning of 2010 Today
    • @jonlives Chef at Etsy
    • @jonlives Chef at Etsy • Open Source Chef Server
 • ~1500 Nodes
 • CentOS, some Mac OS X
    • @jonlives We Love Chef!
    • @jonlives We Know Best.
    • @jonlives Absorb what is useful. Discard what is useless.
    • @jonlives “I am not smart enough to build an ontology … that can encompass all the variations in infrastructure. Nobody is, the world moves too fast.”
    • @jonlives There is no magic pill.
    • @jonlives You are the expert.
    • @jonlives Customizability
    • @jonlives
    • @jonlives Thin Server
    • @jonlives Thick Client
    • @jonlives
    • @jonlives Get Config Data / Initialize • Load client.rb • Server URL • Auth Credentials • Paths • Run ohai • Collect attributes • Plugins!
    • @jonlives Ohai Plugins • Add attributes to your node • Executed at start of run • Single Ruby file • Highest precedence
    • @jonlives Ohai Plugins - v6 provides ‘awesome’ ! awesome Mash.new awesome[:sauce] = "Sricacha" awesome[:level] = "11"
    • @jonlives Ohai Plugins - v7 (Coming soon!) Ohai.plugin(:Awesome) do provides "awesome" collect_data(:darwin) do awesome Mash.new awesome[:sauce] = “Sriracha" awesome[:level] = 11 end end
    • @jonlives Ohai Plugins - client.rb / solo.rb Ohai::Config[:plugin_path] << /<path>/plugins
    • @jonlives Authenticate / Register • Authenticate to Server • <clientkey>.pem • Register if not already registered • <validation>.pem • If both fail, go directly to jail.
    • @jonlives Load / Build Node • Download node • Combine attributes • Expand run_list • Order matters! • Create RunStatus object • Run start handlers
    • @jonlives Handlers • Respond to specific situations • Start, Report, Exception • Common Code
    • @jonlives Handlers - Common Code require "chef/handler" ! class HandlerName < Chef::Handler def report # Ruby code goes here end end
    • @jonlives Handlers - client.rb / solo.rb require “/path_to/mystarthandler.rb" ! my_start_handler = MyStartHandler.new ! start_handlers << my_start_handler
    • @jonlives Synchronize Cookbooks • Get cookbook files list • Only required recipes, files & templates • Compares to local cache • Download changes
    • @jonlives Set up RunContext • Cookbook Collection • Definitions List • Events • Notifications • Node • Resource Collection • Empty for now…
    • @jonlives Events • Respond to interesting events • Pub / Sub model • EventDispatch::Base • Formatter • Custom Subscriber
    • @jonlives Events - Custom Subscriber require “chef/event_dispatch/base" ! class AwesomeSubscriber < Chef::EventDispatch::Base def run_started(run_status) … end # Method for each interesting event end
    • @jonlives Events - Register Subscriber require "chef/handler" require “/path/awesome_subscriber.rb' ! class AwesomeSubscriberStartHandler < Chef::Handler def report event_dispatcher_subscriber = AwesomeSubscriber.new @run_status.events.register(event_dispatcher_subscriber) end end
    • @jonlives Load Cookbook Data • Populate Resource Collection • Libraries • Attributes • Resources / Providers • Definitions • Recipes
    • @jonlives Converge Node • Actually changes node • Apply resource collection • Again, order matters!
    • @jonlives Finalize • Successful Run • Save Node • Report Handlers • Failed Run • Exception Handlers • 💩
    • @jonlives Report & Exception Handlers def report if @run_status.success? # Do a happy dance elsif @run_status.failed? # Sad panda. end end
    • @jonlives Handlers - client.rb / solo.rb require “/var/chef/handlers/mystarthandler.rb" require "/var/chef/handlers/mynewhandler.rb" ! my_start_handler = MyStartHandler.new my_new_handler = MyNewHandler.new ! start_handlers << my_start_handler report_handlers << my_new_handler exception_handlers << my_new_handler
    • @jonlives That RunStatus Object Again… • Accessible to handlers • Run status & timings • Exception and Backtrace • All & updated resources • RunContext • Node object
    • @jonlives Don’t fear the code! • https://github.com/opscode/chef • lib/chef/handler.rb • lib/chef/run_status.rb • lib/chef/run_context.rb • lib/chef/event_dispatch/base.rb
    • @jonlives Um…wat?
    • @jonlives Criteria for Customization Simplicity Modularity Visibility Maintainability Scalability
    • @jonlives November 2014 ! http://jonliv.es/book ! O’Reilly Stand
    • @jonlives Thanks! Questions? ! Office Hours @ 3.15, Marina Room @jonlives / http://jonliv.es / jcowie@etsy.com