Chef Flashcards Preview

DEVOPS > Chef > Flashcards

Flashcards in Chef Deck (78):

What is Chef?

A configuration management platform that provides a way to transforms infrastructure into code and write scripts that are used to automate processes.


What are the main 3 architectural components of Chef

Chef Server, Chef Node, Chef Workstation


What is a Chef Server

The Chef Server is the central store of your infrastructure’s configuration data. The Chef Server stores the recipe and cookbook data necessary to configure your nodes and provides search, a powerful tool that allows you to dynamically drive node configuration based on data.


What is a Chef Node

A Node is any host that is configured using Chef-client. Chef-client runs on your nodes, contacting the Chef Server for the information necessary to configure the node. Since a Node is a machine that runs the Chef-client software, nodes are sometimes referred to as “clients”.


what is a Chef Workstation

A Chef Workstation is the host you use to modify your cookbooks and other configuration data. All the configurations are first tested in the Chef Workstation and then it is forwarded to the Chef Server.


What is Knife

CLI tool that runs on workstation - Knife is used to upload configuration changes to the chef server via ssh


What is a Resource in Chef?

A Resource represents a piece of infrastructure and its desired state, such as a package that should be installed, a service that should be running, or a file that should be generated. A block of Resource can be considered as a Recipe.


What is a Recipe in Chef?

A Recipe is a collection of Resources that describes a particular configuration or policy. A Recipe describes everything that is required to configure part of a system.

Now after the definition I will explain the functions of Recipes by including the following points:

Install and configure software components.
Manage files.
Deploy applications.
Execute other Recipes.


What is a Node in Chef?

any compute resource in your infrastructure that is managed by Chef.


How does a Cookbook differ from a Recipe in Chef?

A Recipe is a collection of Resources, and primarily configures a software package or some piece of infrastructure. A Cookbook groups together Recipes and other information in a way that is more manageable than having just Recipes alone.


What happens when you don’t specify a Resource’s action in Chef?

When you don’t specify a resource’s action, Chef applies the default action.


Are these two Chef recipes the same?
package 'httpd'
service 'httpd' do
action [:enable, :start]
service 'httpd' do
action [:enable, :start]
package 'httpd'

No, they are not. Remember that Chef applies resources in the order they appear. So the first Recipe ensures that the httpd package is installed and then configures the service. The second Recipe configures the service and then ensures the package is installed.


Write a service Resource that stops and then disables the httpd service from starting when the system boots in Chef.

service 'httpd' do
action [:stop, :disable]


How does Chef-apply differ from Chef-client?

Chef-apply is an executable program that runs a single Recipe from the command line. It is a part of the Chef development kit and a great way to explore resources.

Chef-client applies a Cookbook. It is used for production purposes where you typically run Chef-client to apply one or more cookbooks.


What is run-list in Chef?

run-list lets you specify which Recipes to run, and the order in which to run them. The run-list is important when you have multiple Cookbooks, and the order in which they run matters.

Depending on the discussion if you think more explanation is required just mention the below points

A run-list is:

An ordered list of roles and/or recipes that are run in the exact order defined in the run-list; if a recipe appears more than once in the run-list, the chef-client will not run it twice.
Always specific to the node on which it runs; nodes may have a run-list that is identical to the run-list used by other nodes.
Stored as part of the node object on the Chef server.
Maintained using knife, and then uploaded from the workstation to the Chef server, or is maintained using the Chef management console.


What information do you need in order to bootstrap in Chef?

-Your node’s host name or public IP address.
-A user name and password you can log on to your node with.
-Alternatively, you can use key-based authentication instead of providing a user name and password.


How do you apply an updated Cookbook to your node in Chef?

There are three ways to apply an updated Cookbook to a node you can mention all or any one, I will suggest you to mention all three:

Run knife ssh from your workstation.
SSH directly into your server and run chef-client.
You can also run chef-client as a daemon, or service, to check in with the Chef server on a regular interval, say every 15 or 30 minutes.


What is the role of Starter Kit in Chef?

Starter Kit will create the necessary configuration files like chef directory, knife.rb, the ORGANIZATION-validator.pem, and USER.pem files etc. with the correct information that is required to interact with the Chef server.

Now tell how to use Starter Kit, you can simply download the starter kit and then move it to the desired location on your workstation.


What is the command you use to upload a cookbook to the Chef server?

“knife cookbook upload”


What would you set your cookbook’s version to once it is ready to use in production?

According to Semantic Versioning, you should set your cookbook’s version number to 1.0.0 once it is ready to use in production.


What is the value of local development using Test Kitchen in Chef?

Test Kitchen enables you to use a variety of virtualization providers that create virtual machine or container instances locally on your workstation or in the cloud.
It enables you to run your cookbooks on servers that resemble those that you use in production.
It speeds up the development cycle by automatically provisioning and tearing down temporary instances, resolving cookbook dependencies, and applying your cookbooks to your instances.


Where can you get reusable cookbooks that are written and maintained by the Chef community?

Chef Supermarket,


after installing package httpd, how do we check whether it is configured/installed into machines?

sudo service httpd status, If you are using centos: systemctl status httpd.service


what is version control

management of changes to documents, code, computer programs, web sites,
1.0.0 = first int is major release, second int is minor release, third int is patch


Is Chef push or Pull



chef client pull interval (default)

30-35 min


How does chef server install

it uses recipes and cookbooks to deploy chef server


receipes are stored in what kind of file

.rb . ruby


resources in recipes start with a ____ and end with an ____ unless you ______

do,end,take all the defaults


how do you apply a receipe



if you do not specify properties (attributes) in a resource, what do they default to

the class defaults


what is contained in a resource

properties defined by the class
actions defined by the class


multiple actions in a resource get placed in a _____

list [list]


What is pre-convergence

Phase before chef is configured on a node and code linting - ruby-c and foodcritic


What is convergence

Occurs when chef is run on a node and resources are put in the desired state - when you run chef-client


What is post-convergence

After the chef convergence - node is in a verified desired state


What is foodcritic

Foodcritic is a static linting tool that analyzes all of the Ruby code that is authored in a cookbook against a number of rules, and then returns a list of violations.


What is linting

Linting is the process of running a program that will analyse code for potential errors.


What is a provider

providers are what do the work to enforce the desired configuarion - ie yum


what is a resource

A resource is a statement of desired configuration (inside a recipe) for an item. It describes the desired state and steps for achieving the desired configuration


a resource maps to a _____________

provider (which defines the steps to achieve that desired state of configuration)


a chef run is also known as



what is idempotence

can be applied multiple times without changing the result beyond the initial application.


how many components does a resource have



what are the 4 components of a resource

1. resource type
2. resource name
3. resource properties
4. actions to be applied to the resource


what language does chef use



blocks of ruby code start with a ____ and end with an ____

do, end


the default action item for package resource is:



which resource type is not idempotent



the default action item for service resource is:



the default action item for file resource is;



command to execute chef code locally

chef-client --local-mode filename.rb



if first commands exits with no errors, run the second command


how can you add idempotence to an execute resource

add not-if or only_if guards


how do you comment out ruby code



what is a chef custom resource

extension of Chef that adds your own resources and assign properties


not_if prevent a resource from executing when the condition returns as _______



if a recipe is included multiple times in a run-list - how many times will it be executed



typically resources are executed in the order they are written, what can change this behavior

a notifies or subscribes directive


what is a notifies directive

allows a resource to notify another resource to take action


what is a subscribes directive

allows a resource to listen to another resource and take action if the state of the resource being listen to changes


what is a run-list

a run list is a list of cookbooks or recipes that are to be executed on a given node


syntax for including a recipe from an external cookbook

include_recipe 'cookbookname::recipename'


what must be done prior to including a recipe from an external cookbook

create a depandancy in the metadata.rb file in the existing cookbook


what is a chef cookbook

fundamental unit of configuration and policy distribution in chef


what is contained in a cookbook (5)

1. recipes
2. Attribute files
3. file distribution
4. Templates
5. Extentions (libraries, custom resources)


some of the things metadata.rb file contains (3)

1. chef version required to run
2. dependencies
3. versioning
4. cookbook name
5. cookbook maintainer


what is the default recipe filename when creating a cookbook



if you were to include a cookbook without a recipe in a runlist what would it run.



what is happening in here: run_list "recipe{apache::default]"

apache cookbook would run using only the default recipe, no other recipes would be used unless called in default


command to generate a cookbook

#chef generate cookbook


what is a unit test

tests your cookbook resources with an in memory implementation of chef server


purpose of chef environments

separate production testing staging and associate one or more cookbook versions


what is berkshelf

allows you to specify public or private supermarkets and declare cookbooks that you depend on


command to fetch supermarket dependencies

berks install


command to upload supermarket cookbooks and depandancies to chef server

berks upload


what is a wrapper cookbook

allows you to modify the behavior of an upstream cookbook without forking or vendoring them


what is ohai

Ohai is a tool that is used to collect system configuration data, which is provided to the chef-client for use within cookbooks.