Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Introduction to Chef

Introduction to learn the Opscode Chef Cookbook , Recipe for DevOps
by

Amit Patel

on 15 April 2014

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Introduction to Chef

Introduction to Chef
AMIT PATEL
Technical Lead @ Synerzip

More than 8 years experience in Java , J2EE

Enjoy working on new technologies

Whoami
Chef is an automation platform for DEVOPs

A configuration management system

A system integration platform

Infrastructure as code

An API for your entire infrastructure

What is Chef ?
Idempotent

Thick Client - Thin Server

Order Matters

Chef Principles
Your infrastructure
Web Server
DB Server
Web Server
Database Server
Its Growing.........
Web Server
DB Server
Web Server
Database Server
LB Server
Load Balancer
Web Server
Its Growing n Growing .........
Web Server
DB Server
Web Server
Database Server
LB Server
Load Balancer
Web Server
Web Server
DB Server
Web Server
How Chef Works ?
Normal Flow
Chef Architecture
Chef Concepts
Chef-client
runs on system (Node)

Configured or managed systems are called
Nodes

Ohai
a tool to detect a Node environments properties and provide them to the chef-client

Knife
is command line user’s tool for Chef

Workstation
is from where we bootstrap Node.

Resource
defines that Action that needs to be taken
Chef Concepts
Role
is used to define patterns and processes.

A
run-list
is an ordered list of Recipes or Roles that are run in exact order.

A
Data bag
is a global variable and includes sensitive information like password etc..

At a glance
Chef is a system and cloud
infrastructure automation framework
that makes it easy to deploy servers and applications to any physical, virtual or cloud location.

Each chef organization is comprised of
one (or more) workstation
, a
single server
and every
node
that will be configured and maintained by chef.

Cookbooks
(and recipes) are used to tell chef how each node in your organization should be configured. The chef-client (which is installed on every node) does the actual configuration.

Looks Like
Recipe...
Looks Like
Environment
Recipe...
Recipe...
PORT
method
version
directory
location
attributes
Role
PORT
method
version
directory
location
attributes
Node
Recipe...
Recipe...
PORT
method
version
directory
location
attributes
Role
PORT
method
version
directory
location
attributes
Chef Server
The server stores cookbooks, the policies that are applied to nodes, and metadata that describes each registered node.

Types of server:
Hosted Enterprise Chef
Private Enterprise Chef
Open Source Chef

Setup (Hosted Chef)
Signup for opscode hosted chef

https://community.opscode.com

Create an organization (Select your unique one)


Setup (Hosted Chef)
Download user private file
<USERNAME>.pem

Download Organization validation file
<Organization>-validator.pem

Download your knife configuration file
Knife.rb

Setup (Workstation)
Prerequisites
Ruby
Rubygems


Install Chef
Sudo gem install chef
OR
http://www.getchef.com/chef/install/

Setup (Workstation)
Create Chef Repository
Install Git
Git clone git://github.com/opscode/chef-repo.git

Configure Knife
Create .chef directory
Copy below files in .chef directory
private key (<username>.pem) ,
validator (<organization>-validator.pem )
Knife.rb

Template
simply a file that has been marked up to
include variables
(or more
complex logic
)

Resource
Resource take action through
providers
.

Resource will make a
recipe
.

Resource indicates some
action to take
in recipes.

Each Resource have:
Type
Name
Parameters
Action
Notification



Recipe
Perform specific
task
(s) (Executing a
Resource
).

Stored in
cookbook

Executed in
order
they appear

Recipe from other cookbooks can be included with
include_recipe

All the attributes of the current Node are available via the
node
object.


Run list
List of
recipe
and
roles
that a node will run

The order in which recipes are listed in the run-list is exactly the order in chef will run them
Cookbook
A cookbook is like a “
package
” for Chef recipes.
contains recipes, files, templates, attributes, etc.

Required to configure a portion of your infrastructure

Normal cookbook has below structure:
Attributes
Files
Recipes
Templates
metadata.rb

cookbooks for :
apache , java , tomcat , mysql
Attribute
It’s a key-value pair

An attribute is a specific detail about a node.

Usage
Attribute Source
Default attribute in /attributes/default.rb
default["apache"]["dir"] = "/etc/apache2"


Default attribute in /environments/environment_name.rb
default_attributes({ "apache" => {"dir" => "/etc/apache2"}})


Default attribute in /roles/role_name.rb
default_attributes({ "apache" => {"dir" => "/etc/apache2"}})

Default attribute in node object in recipe
node.default["apache"]["dir"] = "/etc/apache2"

Knife
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
data bags
Environments
Searching of data on the server

Common commands
Configure, bootstrap, client, cookbook, search

Environments
An environment is a way to map an organization’s real-life workflow to what can be configured and managed when using server.

Organization have many environments includes :

Development

Test

Staging

Production

Node
Host or server machine that runs the chef-client

Hey there.... Please configure me...
Chef client
Chef-client is an
agent
that runs locally on every node that is registered with the server.


chef-client runs every x minutes and get information about chef-server.


When a chef-client runs, it will perform all of the steps that are required to bring the node into the expected state

How that works ?
Ohai
Tool
that is used to detect attributes on a node, and then provide these attributes to the chef-client at the start of every chef-client run.

Ohai is required by the chef-client and must be present on a node. 

The types of attributes Ohai collects
Platform details
Network usage
Memory usage
Processor usage
Kernel data
Host names
Fully qualified domain names

Node Setup
Bootstrap the node (from workstation)

Knife bootstrap FQDN --sudo –x <username> -P <password> –r ‘recipe[base]’

Update Node (from workstation)

knife ssh name:<node_name> -x <username> -P <password> 'sudo chef-client'

Update Node (from Node)

sudo chef-client

Chef Solo
Simple way to use Chef is using Chef-solo

Doesn’t required server configuration

Easy to test your cookbook & recipe


Setup Chef Solo
Install chef using
curl -L https://www.opscode.com/chef/install.sh | bash

Verify chef-solo
chef-solo –v

Download your cookbook to the machine & test.

Idempotent

Thick Client - Thin Server

Order Matters

Chef Principles
Your infrastructure
Web Server
DB Server
Web Server
Database Server
Its Growing.........
Web Server
DB Server
Web Server
Database Server
LB Server
Load Balancer
Web Server
Its Growing n Growing .........
Web Server
DB Server
Web Server
Database Server
LB Server
Load Balancer
Web Server
Web Server
DB Server
Web Server
How Chef Works ?
Normal Flow
Live Demo
Chef Concepts
Chef-client runs on system (Node)

Configured or managed systems are called Nodes

Ohai a tool to detect a Node environments properties and provide them to the chef-server

Knife is command line user’s tool for Chef

Workstation is from where we bootstrap Node.

Resource defines that Action that needs to be taken
Chef Concepts
Role is used to define patterns and processes.

A run-list is an ordered list of Recipes or Roles that are run in exact order.

A Data bag is a global variable and includes sensitive information like password etc..

At a glance
Chef is a system and cloud infrastructure automation framework that makes it easy to deploy servers and applications to any physical, virtual or cloud location.

Each chef organization is comprised of one (or more) workstation, a single server and every node that will be configured and maintained by chef.

Cookbooks (and recipes) are used to tell chef how each node in your organization should be configured. The chef-client (which is installed on every node) does the actual configuration.

Chef Server
The server stores cookbooks, the policies that are applied to nodes, and metadata that describes each registered node that is being managed by the chef-client.

Types of server:
Enterprise Chef
Hosted Enterprise Chef
Open Source Chef

Setup (Hosted Chef)
Signup for opscode hosted chef

https://community.opscode.com

Create an organization (Select your unique one)


Setup (Hosted Chef)
Download user private file
<USERNAME>.pem

Download Organization validation file
<Organization>-validator.pem

Download your knife configuration file
Knife.rb

Setup (Workstation)
Prerequisites
Ruby
Rubygems


Install Chef
Sudo gem install chef
OR
http://www.getchef.com/chef/install/

Setup (Workstation)
Create Chef Repository
Install Git
Git clone git://github.com/opscode/chef-repo.git

Configure Knife
Create .chef directory
Copy below files in .chef directory
private key (<username>.pem) ,
validator (<organization>-validator.pem )
Knife.rb

Chef Components
Cookbooks

Recipes

Attributes

Templates

Roles

Data bags

Resource
Resource take action through Providers.

Resource indicates some action to take in Recipes.

Each Resource have:
Type
Name
Parameters
Action
Notification



Recipe
Perform specific task(s).

Stored in cookbook

Executed in order they appear

Recipe from other cookbooks can be included with include_recipe

All the attributes of the current Node are available via the node object.


List of recipe that a node will run

The order in which recipes are listed in the run-list is exactly the order in chef will run them
Run list
List of recipe that a node will run

The order in which recipes are listed in the run-list is exactly the order in chef will run them
Cookbook
A cookbook is like a “package” for Chef recipes.
contains recipes, files, templates, libraries, etc.

Required to configure a portion of your infrastructure

Normal cookbook has below structure:
Attributes
Files
Recipes
Resources
Templates
metadata.rb

Attribute
It’s a key-value pair

An attribute is a specific detail about a node.

The chef-client uses six types of attributes to determine the value that is applied to a node during the chef-client run.

Attribute Type
Default
force_default
Normal
Override
force_override
Automatic

Attribute Source
Usage
Default attribute in /attributes/default.rb
default["apache"]["dir"] = "/etc/apache2"

Default attribute in /environments/environment_name.rb
default_attributes({ "apache" => {"dir" => "/etc/apache2"}})


Default attribute in /roles/role_name.rb
default_attributes({ "apache" => {"dir" => "/etc/apache2"}})


Default attribute in node object in recipe
node.default["apache"]["dir"] = "/etc/apache2"

Knife
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
data bags
Environments
Searching of data on the server

Common commands
Configure, bootstrap, knife client, knife cookbook, search

Environments
An environment is a way to map an organization’s real-life workflow to what can be configured and managed when using server.

Organization have many environments includes :

Development

Test

Staging

Production

Node
Host or server machine that runs the chef-client

Hey there.... Please configure me...
Chef client
Chef-client is an agent that runs locally on every node that is registered with the server.


chef-client runs every x minutes and get information about chef-server


When a chef-client is run, it will perform all of the steps that are required to bring the node into the expected state

How that works ?
Ohai
Tool
that is used to detect attributes on a node, and then provide these attributes to the chef-client at the start of every chef-client run.

Ohai is required by the chef-client and must be present on a node. 

The types of attributes Ohai collects
Platform details
Network usage
Memory usage
Processor usage
Kernel data
Host names
Fully qualified domain names

Node Setup
Bootstrap the node (from workstation)

Knife bootstrap FQDN --sudo –x <username> -P <password> –r ‘recipe[base]’


Update Node (from Node)

sudo chef-client

Chef Solo
Simple way to use Chef is using Chef-solo

Don’t required client server configuration

Easy to test your cookbook & recipe


Setup Chef Solo
Install chef using
curl -L https://www.opscode.com/chef/install.sh | bash

Verify chef-solo
chef-solo –v

Download your cookbook to the machine & test.

Agenda
What is Chef?

How Chef works ?

Chef Architecture

Flavor of Chef

Chef components

Installation steps

Live Demo
Amit Patel
Now what ?
Exercise - 1
What we want :
- Want to install apache in the machine and add the sample index.html.
- Change configuration and update node.
How to do that :
- Create a first cookbook "apache".
- Bootstrap first node using knife.
- Create index.html in file and update the recipe to put index.html in node location /var/www/.
- Update the node.
- Check the effect.
Exercise - 2
What we want :
- You have an infrastructure with Load Balancer & Webserver now if you add another Webserver then your load balancer should update with that new node.
How to do that :
- Create 2 Roles (Loadbalancer & Webserver)
- Bootstrap 2 nodes with webserver and loadbalancer role.
- Check the loadbalancer from AWS and see if that server has that node.
- Add another node as a webserver role.
- Now conform that your load balancer should have entry to new node.
We are going to use

CHEF SERVER
Hosted Enterprise Server


WORKSTATION
My Local machine (Ubuntu)


NODE
Amazon EC2 instance (ubuntu)

Success stories
s
Useful resources
https://learnchef.opscode.com/
https://wiki.opscode.com

https://github.com/opscode/chef-repo
https://github.com/amitpatelinfo/chef-training
https://github.com/amitpatelinfo/chef-solo


Thanks
Congratulations... You now
amit.patel@synerzip.com
Full transcript