Chef

Infrastructure automation

Presented by Mauricio Araya V. / @mabrizio

What is chef?

Chef turns infrastructure into code. With Chef, you can automate how you build, deploy, and manage your infrastructure. Your infrastructure becomes as versionable, testable, and repeatable as application code.

Chef Components

Chef Client

A chef-client is installed on every node that is under management by Chef. The chef-client performs all of the configuration tasks that are specified by the run-list and will pull down any required configuration data from the Chef server as it is needed during the chef-client run.

Workstation

One (or more) workstations are configured to allow users to author, test, and maintain cookbooks. Cookbooks are uploaded to the Chef server from the workstation.

Chef Server

The Chef server acts as a hub of information. Cookbooks and policy settings are uploaded to the Chef server by users from workstations.

Ohai

Ohai is a 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.

Data Bag

A data bag is a global variable that is stored as JSON data and is accessible from a Chef server. A data bag is indexed for searching and can be loaded by a recipe or accessed during a search.

Run List

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

Roles

A role is a way to define certain patterns and processes that exist across nodes in an organization as belonging to a single job function. Each role consists of zero (or more) attributes and a run-list.

Environments

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

Cookbooks

An attribute can be defined in a cookbook (or a recipe) and then used to override the default settings on a node. When a cookbook is loaded during a chef-client run, these attributes are compared to the attributes that are already present on the node.

Versions

A cookbook version represents a set of functionality that is different from the cookbook on which it is based. A version may exist for many reasons, such as ensuring the correct use of a third-party component, updating a bug fix, or adding an improvement.

Recipe

A recipe is the most fundamental configuration element within the organization. A recipe:

  • Authored using Ruby.
  • Mostly a collection of resources, defined using patterns.
  • Must be stored in a cookbook.
  • May be included in a recipe.

Recipe Attributes

An attribute can be defined in a cookbook (or a recipe) and then used to override the default settings on a node. When a cookbook is loaded during a chef-client run, these attributes are compared to the attributes that are already present on the node. Attributes that are defined in attribute files are first loaded according to cookbook order.

Data Bags

A data bag is a global variable that is stored as JSON data and is accessible from a Chef server. A data bag is indexed for searching and can be loaded by a recipe or accessed during a search.

Data Bags


{
  "id": "my_app",
  "repository": "git://github.com/company/my_app.git"
}
					

my_bag = data_bag_item("apps", "my_app")
my_bag["repository"]
					

Knife

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

  • Nodes.
  • Cookbooks and recipes.
  • Roles.
  • Environments.
  • Searching of indexed data.

Knife


$ knife node list
$ knife client list
$ knife node show node.fqdn
$ knife environment list
$ knife cookbook list
					

Let's give it a try

Server setup

  • Update/Upgrade your packages
  • Server running ubuntu
  • Install Apache
  • Install PHP
  • Deploy a hello world app

(We'll do everything in the same cookbook)

Thanks