An Introduction to Shef, the Chef Shell


Published on

An overview of Shef, the Chef Shell/debugger.

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Basic Usage\n\nrecipe\nfile "/tmp/ohai2u_chefs.txt" do\n  action :create\nend\nrun_chef\n\nShow That It Worked\n\nls("/tmp")\n\nTurn Off Echo\n\necho off\n\nUsage with Attributes\n\nattributes\nset[:lolcats]='Elliot'\nrecipe\nfile "/tmp/#{node[:lolcats]}.txt" do\n  content "Meow meow Chefs!"\n  action :create\nend\nrun_chef\n\nShow That It Worked Again\n\nls("/tmp")\n\nReset The Run List\n\nreset\n\nShow That Chef Primitives Are Available\n\nChef::Log.level = :debug\nrecipe\nChef::Log.debug ("hello")\n\n
  • \n
  • Setting Breakpoints\n\nreset\nrecipe\necho off\nfile "/tmp/breakpoint-demo.txt" do\n  action :create\nend\n\nbreakpoint "stopping here"\n\nfile "/tmp/breakpoint-demo.txt" do\n  action :delete\nend\n\n
  • \n
  • Interactive Testing of Node Searches\n\nGo to server, "shef -z"\n\nresult = search(:node, "fqdn:whatever")\npp result[0][:kernel][:release]\n\nCan also show result as JSON or YAML, e.g\n\nresult[0].to_json\nresult[0].to_yaml\n\nRunning Chef Recipes in Run List Interactively\n\nOn server, in shef -z do\n\nrecipe\ninclude_recipe "selinux::permissive"\nrun_chef\n\nchef_run.rewind\nchef_run.step\n
  • \n
  • We use the Chef HipChat handler to send failure notices to our HipChat room. Very elementary cookbook here:\n\nThis was on our production DNS server.\n
  • Here is the recipe. We do a search for members matching a domain of interest and iterate over them to create a CNAME to their EC2 public hostname. Clearly, one of the members is missing this attribute due to some runtime error.\n
  • \n
  • Shef to the rescue!\n
  • Run Shef on production DNS master, literally start typing in the recipe that is failing. Look, host3 is the one which is broken. Now I can log into host3 and see what is wrong with it.\n
  • \n
  • \n
  • \n
  • An Introduction to Shef, the Chef Shell

    1. 1. Shef: The Chef Shell Julian C. Dunn Senior Systems Operations Engineer
    2. 2. What is SecondMarket? Since 2004, SecondMarket has been committed to connecting the world’s qualified investors with alternative investments. Our Vision: To revolutionize the financial markets by creating a Trading trusted global platform to more efficiently allocate capital Providing institutional investors with access to through technology-enabled solutions. unique fixed income products, independent market perspective, and superior client service SecondMarket is organized into three business segments: Markets Creating an enterprise solution for private issuers to help them facilitate secondary trading and raising primary capital in a company-controlled manner neXus Aggregating, standardizing and promoting next generation investments to make them available to the broadest group of investors ever assembledMember FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    3. 3. What is Shef? Chef running within IRB Three modes: Standalone ("-a") Solo ("-s") Client ("-z") Use existing config file or shef.rbMember FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    4. 4. SecondMarket Infrastructure 75-100 servers Hosting: Amazon EC2 Technologies: Java (Spring MVC), Scala, Play! Framework, PostgreSQL, Mongo, Redis, Couchbase Server, ActiveMQMember FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    5. 5. Main Uses of Shef Quick prototyping Syntax checking Debugging recipes Poke around Chef Server in familiar Ruby environmentMember FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    6. 6. Shef Standalone Demo 6
    7. 7. Commands and Modes Default prompt Attribute mode Recipe mode Run Chef Other useful commandsMember FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    8. 8. Debugging Recipes 8
    9. 9. Summary Setting breakpoints chef_run.rewind chef_run.skip_forward and skip_backwards resources commandMember FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    10. 10. Using Shef as a Client 10
    11. 11. Shef as a Client Interactive testing of node searches Step through one or more recipesMember FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    12. 12. Debugging Production Issues 12
    13. 13. HipChat Chef RoomMember FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    14. 14. zones.erb 29: <% @members.each do |member| -%> 30: <%= member[hostname] %> IN CNAME <%= member[ec2][public_hostname] %>. 31: <% end -%>Member FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    15. 15. Which member is causing this to screw up?Member FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    16. 16. Which member is causing this to screw up?Member FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    17. 17. [jdunn@dns1 ~]$ shef -z loading configuration: /etc/chef/client.rb Session type: client . . chef > echo off chef > members = search(node, "") chef > members.each do |m| chef > pp "#{m[hostname]}, #{m[ec2] [public_hostname]}" chef ?> end "host1," "host37," "host3, " NoMethodError: undefined method `[] for nil:NilClassMember FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    18. 18. Limitations of Shef Can’t modify run list w/o resetting Attributes mode changes don’t propagate to recipes Client mode cant operate on local cookbooks - must upload to the server (just like a regular Chef client) And yes, the name is confusing. It’s being changed: http:// FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    19. 19. Thanks! @julian_dunn Yes, we’re hiring!Member FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.
    20. 20. Disclosure This document is intended for those with an in-depth understanding of the high risk nature of alternative investments and these investments may not be suitable for you. This document may not be distributed in either excerpts or in its entirety beyond its intended audience and SecondMarket will not be held responsible if this document is used or is distributed beyond its initial recipient or if it used for any unintended purpose. This document is not a solicitation for an order, and there is not enough information contained in this message in which to make an investment decision and any information contained herein should not be used as a basis for this purpose. To the best of our knowledge, this document and relevant pages are: current as of the date of distribution; subject to change without notice; directed solely at eligible institutional buyside and/or sellside clients, qualified purchasers, qualified institutional brokers and other professional clients; not directed at, may not be suitable for and should not be relied on by general retail clients. SecondMarket does not: produce in-house research; make recommendations to purchase or sell specific securities; provide investment advisory services; and conduct a general retail business. By reading this document you acknowledge that you are not a general retail client. If you are a general retail client then this document is not intended for you. Alternative investments may not be suitable investments for you and you may not possess the sophistication to rely on its contents and should either shred or return to SecondMarket. Neither SecondMarket, its affiliates, nor any of its directors, officers, employees or agents shall have any liability, howsoever arising, for any error or incompleteness of fact or opinion in it or lack of care in its preparation or publication; provided that this shall not exclude liability to the extent that this is impermissible under securities laws. All statements and opinions are liable to change without notice. The SecondMarket logos, graphics, icons, trademarks, service marks and headers appearing herein are service marks, trademarks (whether registered or not) and/or trade dress of SecondMarket Holdings, Inc. (the “Marks”). All other trademarks, company names, logos, service marks and/or trade dress mentioned, displayed, cited or otherwise indicated herein (“Third Party Marks”) are the sole property of their respective owners. The Marks or the Third Party Marks may not be copied, downloaded, displayed, used as metatags, misused, or otherwise exploited in any manner without the prior express written permission of SecondMarket or the owner of such Third Party Mark.Member FINRA | MSRB | SIPC © 2012 SecondMarket Holdings, Inc.