Cheffing Your DevOps - Apistek

Transcription

Cheffing your DevOpsMichael Ducy – Chef – @mfdii

What is Chef?Short Answer: An Automation Frameworkfor automating infrastructure and applications

Traditional Systems ManagementConfig 1Config 2Config 3

Traditional Systems ManagementConfig 2Config 3AutomationConfig 1

Idea of ServicesConfig 1Config 2Config 3AutomationService

Abstraction of ServicesConfig 1Config 2Config 3AutomationService

Chef is Infrastructure as Code Programmatically provisionand configure 295187/

Chef is Infrastructure as Code Treat like any other 5187/

Chef is Infrastructure as Code Reconstruct business fromcode repository, databackup, and b/4555295187/

Chef is Infrastructure as Code Programmatically provision andconfigure components Treat like any other code base Reconstruct business fromcode repository, databackup, and b/4555295187/

The Chef Software PlatformManagementConsoleHigh Availabilityand ReplicationAnalyticsPlatformChefClientNodesChef ServerCookbook andPolicy AuthoringChefDevelopment KitDataCenterTest-DrivenInfrastructureTheCloud

Building BlocksCookbooksRecipesResources

Building Blocks: What is a Resource? A Resource is a system state you defineExample: Package installed, state of a service, configuration file existing You declare what state you want the resource in.Chef automatically determines HOW that state is achievedOn Linux based OSes:On Windows based OSes:

Resource Example#windowsdsc resourceresourcepropertypropertyend'webserver' do:windowsfeature:name, 'Web-Server':ensure, 'Present’

Resource Example#linuxpackage "httpd" doaction :installend

Building Blocks: What is a Recipe? An abstraction of a Service that consists of a set of Resourcesto deliver that Service Resources are executed in the order they are listed.

Recipe Example#linuxpackage "httpd" doaction :installendinclude recipe "apache::fwrules”service "httpd" doaction [ :enable, :start ]end

Recipe Example#windowsinclude recipe "fourthcoffee::dsc”include recipe "iis::remove default site”remote directory node['fourthcoffee']['install path'] dosource 'fourthcoffee’action :createendiis pool 'FourthCoffee' doruntime version "4.0"action :addendiis site 'FourthCoffee' doprotocol :httpport 80path node['fourthcoffee']['install path']application pool 'FourthCoffee'action [:add,:start]end

Cookbooks A Higher Level Abstraction of a Service A set of Recipes and Data Attributes requiredto deliver one or multiple Services

Define cookbook rt'] 80

Consume cookbook attributeiis site 'FourthCoffee' doprotocol :httpport node['fourthcoffee']['port']path node['fourthcoffee']['install path']application pool 'FourthCoffee'action [:add,:start]end

Demo!

Yes!

That’s cool but Things break Chef is a language (based on Ruby) How can you rapidly develop recipes and cookbooks?

Let’s step back

Automation PatternsCI/CDClick toComputeITAutomation

Also known as You’ll never get toContinuous Deploymentclicking a GUI

Theory of testing Testing builds safety

Feedback loops Tell us we’re doing the right thing At the right time With the right results

Feedback loops Measurements we take to ensure the“experiment” is behaving as expected

Tests are essentially feedback loops

Remember Chef is “Infrastructure as Code”

Remember “Infrastructure as Code” should betreated like ANY other codebase.

Treated Any Other Codebase Stored in SCM Testing Coverage Part of your CI pipelines

Testing in Chef Chef recipes need testedLintingStatic AnalysisUnit TestingFunctional Testing

Food CriticTest Your “Chef Style” Flag problems that might cause your Chef cookbooks to fail onconvergeFC010: Invalid search syntax Identify style/convention that has been adopted by the Chef communityFC004: Use a service resource to start and stop services Create custom rules for your own organization’scompliance/standardsCOMP001: Do not allow recipes to mount disk volumes

Rubocop Identify potential Ruby errorsUnclosed strings, etc. Identify style/convention that helps write better codeSingle quotes vs. double quotesThis is useful for new Chefs, and helps make the code more readable

ChefSpecSimulate Chef Did I send a properly formed piece of code to Chef? Especially important if there is mutability in your code Useful for regression testing – to make sure new changes don’tbreak stuff that worked before.

Test KitchenLet’s do this (almost) for real “Executes your Chef code on an actual, factual node These nodes should be disposable (local virtualization, cloud instances, etc.) Use any number of testing products to ensure expected resultsBATSServerSpecPester Can pull in other cookbook dependencies as well, and execute against a machinethat looks the same as your standard image

Demo!

Summary Chef is awesome Testing is important Feedback loops build safety Goal is to eliminate waste

Questions?Cheffing your DevOpsMichael Ducy – Chef – @mfdii

Can pull in other cookbook dependencies as well, and execute against a machine that looks the same as your standard image . Demo! Summary Chef is awesome Testing is important Feedback loops build safety Goal is to eliminate waste . Questions? Cheffing your DevOps Michael Ducy - Chef - @mfdii . Title: Cheffing your DevOps