Infrastructure as Code: Introduction to Chef

Ac32e9f15e9bc8f79a1ca4806b8cd760?s=47 Jesse Dearing
September 04, 2012

Infrastructure as Code: Introduction to Chef

The full stack: the final frontier. As developers we take problems and use code to describe the proposed solution to solve the problem using the resources available to us. Infrastructure as Code is a way of codifying the installation of services and software on a machine starting with a fresh image.

This session explores infrastructure as code using Chef and will allow you to manage your infrastructure as resources in code vs. a slew of shell scripts. In addition, talk about Chef testing techniques.

Ac32e9f15e9bc8f79a1ca4806b8cd760?s=128

Jesse Dearing

September 04, 2012
Tweet

Transcript

  1. Infrastructure as Code with Chef http://www.fotopedia.com/items/flickr-2572841582

  2. Jesse Dearing @JesseDearing Full Stack Developer

  3. None
  4. Front-end (HTML, JavaScript) App (Ruby) Data Models (Ruby) Database (PostgreSQL,

    MySQL) OS (Linux) I work in all these layers Infrastructure as Code and Chef live here
  5. I work for

  6. Dependency Resolution Time To understand Chef you have to understand

    Infrastructure as Code
  7. Dependency Resolution Time To understand you have to understand Infrastructure

    as Code Devops
  8. Dependency Resolution Time To understand you have to understand Devops

    writing and running software
  9. What is DevOps?

  10. Developers and Operations

  11. Developers and Operations X vs

  12. Fight!

  13. Developers ‣Write buggy code ‣Do not develop on systems that

    look like production ‣Builds features to throw over the wall ‣Think that understanding infrastructure is not their problem Operations ‣Stands in the way of deployments ‣Mostly reactive to issues as alerts are triggered ‣Rolls back code that works on my box™ ‣Think that understanding architecture is not their problem ‣Think that understanding architecture is not their problem ‣Think that understanding infrastructure is not their problem
  14. Developers Operations ‣Think that understanding architecture is not their problem

    ‣Think that understanding infrastructure is not their problem
  15. None
  16. DevOps is about breaking down silos Code inventory (software not

    deployed to production) has no business value Only shipped code has value Devs and Ops are responsible for shipping Give and take: devs take the pager to assist with software issues and ops codifies processes Dev and Ops need to speak a common language
  17. Infrastructure as Code

  18. Infrastructure is composed of ๏CPU ๏Memory ๏Network ๏Disks ๏Remote Storage

    ๏Virtual Machines ๏Policy Configuration ๏Firewalls ๏Services
  19. Infrastructure is composed of ๏CPU ๏Memory ๏Network ๏Disks ๏Remote Storage

    ๏Virtual Machines ๏Policy Configuration ๏Firewalls ๏Services CODE Resources
  20. So I just commit all my shell scripts? ಠ_ಠ

  21. Shell scripts always need tweaking You can’t run shell scripts

    against a given criteria of servers Shell scripts take a lot of work to make idempotent There is a better way!
  22. Introducing Chef

  23. 3 ways of using Chef Chef Solo Chef Server Hosted

    Chef
  24. 3 ways of using Chef Chef Solo Chef Server Hosted

    Chef
  25. Chef Solo Write resources Recipes, Data Bags, Roles

  26. Chef Solo Write resources Execute them Recipes, Data Bags, Roles

    Chef-solo
  27. Chef Solo Write resources Execute them Installs packages, creates files,

    etc. Recipes, Data Bags, Roles Chef-solo Updates system state
  28. Chef Solo Write resources Execute them Installs packages, creates files,

    etc. Recipes, Data Bags, Roles Chef-solo Updates system state Meh.
  29. Only slight improvement over shell scripts But it’s great for

    testing your Chef scripts before uploading them to the server
  30. 3 ways of using Chef Chef Solo Chef Server Hosted

    Chef
  31. Node that polls with chef-client chef-server Polls server periodically for

    run list or data changes
  32. Node that polls with chef-client chef-server Also sends back metadata

    about the node using Ohai
  33. Node that polls with chef-client chef-server Also sends back metadata

    about the node using Ohai My laptop Modify recipes, search nodes, change variables
  34. Ohai Gathers metadata from the node to send back to

    Chef server •Installed languages •CPU •Kernel version •Settings •IP Address •Users •Groups (Oh, hi)
  35. 3 ways of using Chef Chef Solo Chef Server Hosted

    Chef
  36. OpsCode runs your chef-server

  37. user "foobar" file "/etc/service.conf" do mode '0640' owner 'foobar' end

    package "nginx" execute "/usr/bin/somecommand" Recipe Example
  38. Recipes can be shared and committed to source control

  39. None
  40. Configuration is stored on the Chef server API keys, passwords,

    environment/role/instance specific data
  41. Let’s see how the MySQL recipe sets the root password

  42. Chef’s best friend: He’s a Vagrant

  43. Defines VirtualBox VMs Creates using CLI Forwards ports Tears down

    VMs
  44. None
  45. Questions?

  46. Thanks!