Introduction to Chef

Rails back to basics: Introduction to Chef

Roy Cruz

by

Roy Cruz

Rails back to basics: Roy Cruz

Ruby on Rails Developer in

Growth Acceleration Partners

rcruz@weaegap.com

 

facebook.com/railscostarica

Agenda

Rails back to basics: Agenda

  • Overview of Chef
    • What is Chef?
    • Who use it?
    • How does it work?
    • Pros/Cons
    • Alterntives
  • Definitions​
    • Workstation
    • Node
    • Resource
    • Recipe
    • Cookbook
    • Roles
    • run-list
  • Commands
    • knife
    • chef-client

Overview of Chef

What is Chef?

Rails back to basics: What is Chef?

Chef is a systems and cloud infrastructure automation framework that makes it easy to deploy servers and applications to any physical or virtual, no matter the size of the infrastructure. It automates how applications are configured, deployed, and managed across your network, no matter its size.

Who use Chef?

Rails back to basics: What is Chef?

Pros/Cons

Rails back to basics: What is Chef?

  • High Flexibility.
  • Great tool documentation
  • High customization
  • Great Community
  • Can implement version control system
  • High Learning Curve
  • For some features you need to pay for the enterprise edition
  • Learning of another programming language

Alternatives

Rails back to basics: What is Chef?

How does it work?

Rails back to basics: What is Chef?

Chef Server

Workstation

Node

chef-client

run-list

knife

Definitions

Workstation

Rails back to basics: Definitions

A workstation is a computer that is configured to run knife, to synchronize with the chef-repo, and interact with a single Chef server. The workstation is the location from which most users will do most of their work.

Node

Nodes represents the servers in the infrastructure, can be physical or virtual.

Rails back to basics: Definitions

Resources

  • Files
  • Users
  • Directories
  • Symlinks
  • Groups
  • Filesystems
  • Services
  • Packages
  • Mounts

Rails back to basics: Definitions

Recipe

Configuration files that describe resources and their desire state.

Recipes can:

  • Install and configure software
  • Manage files
  • Deploy applications
  • Execute other recipes

Rails back to basics: Definitions

Recipe Sample

package 'apache2'

service 'apache2' do
  action [:start, :enable]
end

template '/var/www/html/index.html' do
  source 'index.html.erb'
end

Rails back to basics: Definitions

Cookbook

A cookbook defines a scenario and contains everything that is required to support that scenario:

  • Recipes that specify the resources to use and the order in which they are to be applied
  • Attribute values
  • File distributions
  • Templates
  • Extensions to Chef

Rails back to basics: Definitions

Simple Cookbook Structure

.
├── Berksfile
├── chefignore
├── metadata.json
├── metadata.rb
├── README.md
├── recipes
│   └── default.rb
└── templates
    └── default
        └── index.html.erb

Rails back to basics: Definitions

Run-List

A run-list defines all of the configuration settings that are necessary for a node to be put into the desired state. A run-list is:

  • An ordered list of roles and/or recipes that are run in an exact order
  • Always specific to the node on which it runs
  • Stored as part of the node object on the Chef server
  • Maintained using knife and uploaded to the Chef server

Rails back to basics: Definitions

Roles

Roles represent the types of servers in your infrastructure Load Balancer, Application Server, Database Cache, Database, Monitoring.

 

Roles may include a list of Chef configuration files that should be applied (this is called run-list) , also it should include data attributes necessary for configuring infrastructure.

Rails back to basics: Definitions

Commands

Knife

Rails back to basics: Commands

Knife is a command-line tool that provides an interface between a local chef-repo and the Chef server. Knife helps users to manage:

  • Nodes
  • Cookbooks and recipes
  • Roles
  • Stores of JSON data (data bags)
  • Environments
  • Cloud resources, including provisioning
  • The installation of the chef-client on management workstations

chef-client

A chef-client is an agent that runs locally on every node that is under management by Chef. When a chef-client is run, it will perform all of the steps that are required to bring the node into the expected state.

Rails back to basics: Commands

chef-client steps

1. Registering and authenticating the node with the Chef server

2. Building the node object

3. Synchronizing cookbooks

4. Compiling the resource collection by loading each of the required cookbooks

5. Taking the appropriate and required actions to configure the node

6. Looking for exceptions and notifications, handling each as required

Rails back to basics: Commands

Questions?

Questions?

Rails back to basics: Questions?

Sources

Harvey, N. (n.d.). Chef Fundamentals Module 1. Retrieved March 15, 2015, from https://learn.chef.io/screencasts/fundi-webinar-week-1/

About Knife. (n.d.). Retrieved March 15, 2015, from https://docs.chef.io/knife.html

Chef-client. (n.d.). Retrieved March 15, 2015, from https://docs.chef.io/chef_client.html

Workstations. (n.d.). Retrieved March 15, 2015, from https://docs.chef.io/workstation.html

Rails back to basics: Sources

All about Chef. (n.d.). Retrieved March 15, 2015, from http://docs.chef.io/

About Nodes. (n.d.). Retrieved March 15, 2015, from https://docs.chef.io/nodes.html

About Cookbooks. (n.d.). Retrieved March 15, 2015, from https://docs.chef.io/cookbooks.html

About Roles. (n.d.). Retrieved March 15, 2015, from https://docs.chef.io/roles.html

Sources

Rails back to basics: Sources

Networking 101: Puppet and Chef. (n.d.). Retrieved March 15, 2015, from https://www.youtube.com/watch?v=B5assieBDy8

Marschall, M. (2013). Chef Infrastructure Automation Cookbook. Packt Publishing.

Sources

Rails back to basics: Sources

Made with Slides.com