The guide helps you understand how Chef works. It will also demonstrate about the primary usage and getting started with installing Chef-Solo over your workstations.
However, it will also help you to figure out how to configure Chef Server, Knife and Chef-Client at your stack making it possible to let them all communicate together.
2. High-level Overview
● A library for configuration management.
● A configuration management system.
● A system integration platform.
● An API for your entire infrastructure.
● Change Management made simple.
4. Problems
● You are just an engineer.
● DevOps were never meant to you.
● ~N horizontal scaling nodes.
● System in Production, Images aren’t synced.
● Reflect a change to all nodes without doing
that manually.
● Generic practice missing.
5. More problems?
● OS packages been updated frequently.
● Inject / Reject any dependency anytime from
entire cluster.
● Multiple clusters of differentiated stack i.e
(App Cluster, MySQL Cluster, glusterFS
cluster).
● Tired of manual SSH connections to each
machine.
6. Infrastructure Specs
● Manages configuration as Idempotent
Resources.
● Merge them together in Recipe.
● Version Control System on the bottom.
● Keeps underlying generic configuration
separate from `client` environment.
● Extendable and replicable.
7. Infrastructure as Code
A technical domain revolving around building
and managing infrastructure programmatically.
Enables the reconstruction of the business from
nothing but a source code repository, an
application data backup and bare metal
resources. All you’ve to do is to take care of
middleware building your stack instead of
nodes, itself.
8. Chef Client
● CLI deployed over node.
● Communicates with Chef Server to pull
configuration and updates.
● Should exists on each node apart of the
belonging role cluster.
● Carries unique IP and name providing
independent identity in server
9. Chef Server
Chef Server is the major man in the entire
workflow. It communicates with `knife` and
`chef-client` and at the mean time, it also
collaborate to persist recipes and cookbooks of
configuration with versioning so that, `chef-
client` could ask for relevant configuration
later.
10. Knife
`Knife` is a command-line tool, providing an
ability to communicate with Chef Server and
indirectly with chef-client. If you actually want
to make changes over each ~N node configured
in your Chef- `knife` would be responsible for
passing an argument to `Chef Server` and that
will take care of `chef-client` (nodes) itself.
11. Cookbook
A cookbook is the fundamental unit of
configuration and policy distribution. A
cookbook defines a scenario and contains
everything that is required to support that
scenario. Measuring Recipes, Attributes, File
distribution and Templates.
12. Recipe
Its a fundamental unit of cookbook. It should
reside inside `cookbook` respectively.
However, `Recipe` could be written using
`Ruby` language exposing the behavior to be
done on the client. It should define everything
that is required to configure part of a system.
Recipe could be inherited or included inside
another recipe and could be a dependency for
13. Role
Role is a deliberate tag, assigned to each node
individually making it possible for every node
in a cluster to demonstrate and individually
recognize themselves. Roles usually allow us to
group individual nodes of the cluster to be
recognized based upon the task we’re supposed
to be taken from them.
14. Run List
● Should exists in node (`chef-client`).
● run_list occupies `recipe` and `roles`
related to the node.
● “run_list”: [
“role[api]”,
“recipe[apt]”, “recipe[redis]”
]
16. Abbr
● package: Used to manage packages on a node.
● service: Used to manage service on a node.
● user: Manage user on a node.
● group: Manager user groups.
● template: Manage files with ruby templates.
● cookbook_file: Transfer file from cookbook to node.
● file: manage content of a file on node.
● directory: manage directories on a node.
● execute: Executes a command on a node.
● CRON: Edit an existing cron file on a node.
19. bash "install_redis" do
user 'root'
cwd "/home/hamza"
code <<-EOH
wget http://download.redis.io/releases/redis-3.0.0.tar.gz
tar -xvf redis-3.0.0.tar.gz
cd redis-3.0.0/
make install
EOH
end
execute "Start Redis Server" do
command "redis-server &"
end
30. $ mkdir -p ~/chef-repo && cd $_;
// Assuming, you have `knife` installed
$ knife cookbook create nginx
$ cd cookbooks/nginx;
// ls: attributes, CHANGELOG.md, definitions, files, libraries, metadata.rb, providers, README.md,
recipes, resources, templates
$ nano recipes/default.rb;
package ‘nginx’ do
action :install
end
service ‘nginx’ do
action [ :enable, :start ]
end
cookbook_file “/usr/share/nginx/www/index.html” do
source “index.html”
mode “0644”
end
31. Upload to Chef-Server
Once, we’re done with all the basic
configurations and writing our recipes inside
cookbook - it’s now ready to be uploaded to
Chef Server.
PS: `chef-client` (node) will pull the cookbook
from Chef Server