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

Chef Intro

An introduction to Opscode Chef, (or chef newbies)
by

Tikal Knowledge

on 7 August 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Chef Intro

Nodes

yet

are another object in your infrastructure, it will usually represent a single host, physical / virtual
On the Node we will find a chef client which is the one performing the "heavy lifting"
The client runs
ruby code
which applies configuration [to itself]

based on a set of
attributes
This entire process is
referred to as a
run list

A component of the
Chef Client
is
Ohai
which discovers data about the node, info like disk, ram, ip address, FQDN etc etc.
chef-client
{
ohai
Virtual
chef-client
ohai
Physical
{
{
{
Search
Admin UI
}
-
-
}
}
-
-
}
}
}
-
-
}
Knife
{
}
{
Workstation(s)
Chef-Server
Nodes
Environment
Cookbooks
Recipes
Attributes
Roles
Data bags
Versions
Repository
Settings
Data bags
Roles
Environment
}
{
}
{
Run-list
Default
Attributes
Recipes
Cookbooks
Versions
Policy
Admin UI/API
Search
Attributes
Node object
How does
do it ?
Introduction
"My personal Test lab"
My laptop :: Ubuntu 12.10 host [Desktop edition]
Virtual Box [4.2.2]
Vnet0 172.20.20.1 [172.20.20.0/24] + ipforwarding and iptables MASQ.
Dnsmasq for dns + dhcp
milkyway.local private domain name for local hosts
csrv for OSS Chef Server [CentOS-5.8]
cws for Chef workstation [ ubutnu srv 10.04 ]
n1e1 + n2e1 for "environment #1"
n2e1 + n2e2 for "environment #2"
Chef Repo
Starting point
"_default env always configured and cannot be edited
Configure knife:
1. On Chef server create an admin user
2. On Workstation install Chef
3. Copy user to workstation
4. Knife configure
Currentely there are no "nodes" to manage
} Default users
Admin user
Add Some nodes
Using Chef strap
We now have 4 nodes managed by chef
Environment(s)
I would usually use
Knife
for this kind of query ...
tikal@cws:~$ knife environment create 'dev'
Create environment from file:
tikal@cws:~/chef-repo$
knife environment from file prod.json
Use 1080p
Infrastructure
as Code
Use OpsCode Chef's repository as base structure (you don't have to)
tikal@cws:~$
git clone git://github.com/opscode/chef-repo.git
Traceable and "Owned" infrastructural changes
Add remote repository [default remote is opscode ... ]
tikal@cws:~/chef-repo$
git remote add github https://github.com/tikalk/chef-intro-repo.git
[your custom url]
git push
github
master
This intro's git repo is:
https://github.com/tikalk/chef-intro-repo
edit an existing env "from file":
knife edit from file environments/prod.json
Cookbooks
Add an existing node to an environment
tikal@cws:~$
knife node edit n1e1.milkyway.local
Saving updated chef_environment on node n1e1.milkyway.local
Chef In Practice
"Play Ground" / Setup
Hello
Setting up OSSCS
In this Intro, chef server was installed on CentOS 5.8 via Git
git clone
https://github.com/tikalk/chef-server-install.git
cd chef-server-install
./setup.sh all


issues / suggestions / forks are welcome
to Chef
Chef-Validator
&
node key
Admin User
“Today we are SURE that we made the right decision, choosing Tikal”Guy Ben-Porat - Development Manager “ExLibris”

ALM





We help companies build, deliver,
deploy, manage and optimize their products.

JAVA

RoR

.NET

JS
12+ Years old
90+
Tikal’s
Experts Team
100+
Projects
Last Year
460+
Meet up
Members
150+
Blog Posts
Last Year
1600+
Community
Members
“Actions speak louder than words”
Tikal's motto
Tikal by Numbers
Whoami ?
Haggai Philip Zagury
Devops & Configuration management Engineer
“I am a member of Tikal's ALM group.
With over 12 members, we meet, share, contribute and code together on a monthly basis. “
http://www.facebook.com/TikalKnowledge?fref=ts
https://twitter.com/tikalk

Knife is like a pipe + tee
One side you create / edit and commit
On the other you push to Chef Server
Knife | tee repo | tee chef server
Test your recipes locally then commit ...
Roles
Setting up A Workstation
perquisite :: Chef Server
Clone and existing cookbook(s)
tikal@cws:~/chef-repo$
knife cookbook site install chef-client
Cookbook chef-client version 2.1.6 successfully installed
A good time to mention
providers
libraries
templates
files
What is Chef & what does it solve
Chef components chef-server, chef-client, knife etc
Chef environment intro
Setting up Chef server
Setting up Chef Workstation (knife conf)
chef bootstrap, [webui/api/search]
chef client [configuring & running]
Introduction to Cookbooks
Reusing existing cookbooks
Writing your own cookbooks
cookbook deployment
SCM integration (git)
Open Questions Time.
Agenda
Why ?
Care to probe angry sysadmins @ 2 AM ?
Now, seriously
It's flexible [not OS specific !? - debatable]
A set of tools for each daunting task
DRY - Don't repeat yourself / D&F
Infrastructure as code
As you "
mature with chef
" you will learn of more great reasons ...
Ubuntu perquisites:
tikal@cws2:~$
sudo apt-get install ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert curl

Ruby Gems:
tikal@cws2:/tmp$
curl -O http://production.cf.rubygems.org/rubygems/rubygems-1.8.10.tgz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 243k 100 243k 0 0 168k 0 0:00:01 0:00:01 --:--:-- 344k
tikal@cws2:/tmp$
tar zxf rubygems-1.8.10.tgz
tikal@cws2:/tmp$
cd rubygems-1.8.10
tikal@cws2:/tmp/rubygems-1.8.10$
sudo ruby setup.rb --no-format-executable
RubyGems 1.8.10 installed

Install Chef Gem
tikal@cws2:/tmp/rubygems-1.8.10$
sudo gem install chef --no-ri --no-rdoc
tikal@cws2:
scp root@csrv:/etc/chef/*.pem ~/.chef
tikal@cws2:~$
knife configure -i
WARNING: No knife configuration file found
Where should I put the config file? [/home/tikal/.chef/knife.rb]
Please enter the chef server URL: [http://cws2.milkyway.local:4000]
http://csrv:4000
Please enter a clientname for the new client: [tikal]
cws2
Please enter the existing admin clientname: [chef-webui]
Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]
/home/tikal/.chef/webui.pem
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef/validation.pem]
/home/tikal/.chef/validation.pem
Please enter the path to a chef repository (or leave blank):
/home/tikal/chef-repo/
Creating initial API user...
Created client[cws2]
Configuration file written to /home/tikal/.chef/knife.rb
Validating workstation setup
Create your own
based on http://wiki.opscode.com/display/chef/Guide+to+Creating+A+Cookbook+and+Writing+A+Recipe
{
}
some knife
commands
19 hours ago, n2e2.milkyway.local, n2e2.milkyway.local, 172.20.20.214, centos 6.3.
19 hours ago, n1e1.milkyway.local, n1e1.milkyway.local, 172.20.20.243, ubuntu 12.04.
19 hours ago, n1e2.milkyway.local, n1e2.milkyway.local, 172.20.20.196, ubuntu 12.04.
19 hours ago, n2e1.milkyway.local, n2e1.milkyway.local, 172.20.20.211, centos 6.3.
tikal@cws:~/chef-repo$
knife client show n1e1.milkyway.local
_rev: 1-9c89a9b27a012fdbb4d9f00a0a93748d
admin: false
chef_type: client
json_class: Chef::ApiClient
name: n1e1.milkyway.local
public_key: -----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAtTFjQMx9GgpUOoh+AnjDf9vYg8owQMucs5QyrlpWgXGLScsh4iXE
zxpMNYqPxzjwnCIiIZRaNkAxc0p8YiTzZcgPYUvYLhe4I88z3+WfOBwR2Bc7TKx1
mwuJu0ytzl3GQ4SAJykTZkutTL8WVc2/FExFqB8cPo8hI3ZUZjjJ5ayJGZ1RKNo0
0DHshUh1UDSNzMHkBEHv6e9R/xiTkPxyJxKB8cEO1BmPP/hE2ASlS+GjKInqkbNO
ogCgLaX7vP0jhnnjAXZXJtHznIlF6FNmcbQB1xkwspSMcoH64fFIS3jgJR40EBU0
K9XoiYGu1DWMkC3qPUuBWVL4A+ryC1psNQIDAQAB
-----END RSA PUBLIC KEY-----
tikal@cws:~/chef-repo$
knife client show n1e1.milkyway.local
{
"name": "n1e1.milkyway.local",
"public_key": "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAtTFjQMx9GgpUOoh+AnjDf9vYg8owQMucs5QyrlpWgXGLScsh4iXE\nzxpMNYqPxzjwnCIiIZRaNkAxc0p8YiTzZcgPYUvYLhe4I88z3+WfOBwR2Bc7TKx1\nmwuJu0ytzl3GQ4SAJykTZkutTL8WVc2/FExFqB8cPo8hI3ZUZjjJ5ayJGZ1RKNo0\n0DHshUh1UDSNzMHkBEHv6e9R/xiTkPxyJxKB8cEO1BmPP/hE2ASlS+GjKInqkbNO\nogCgLaX7vP0jhnnjAXZXJtHznIlF6FNmcbQB1xkwspSMcoH64fFIS3jgJR40EBU0\nK9XoiYGu1DWMkC3qPUuBWVL4A+ryC1psNQIDAQAB\n-----END RSA PUBLIC KEY-----\n",
"admin": false,
"json_class": "Chef::ApiClient",
"chef_type": "client",
"_rev": "1-9c89a9b27a012fdbb4d9f00a0a93748d"
}
tikal@cws:~/chef-repo$

knife status
-Fj
(Return as json)
A simple chef recipe
A simple role
role + nested role
including discussed recipes (chef-server + ntp)
knife node edit
add role for the node
use override_attribute to override defaults
NODE
Quick Dip
http://wiki.opscode.com/display/chef/Architecture
<= Scale =>
<= Rest =>
install package
create file from template
start & enable service
role name
include recipe
Or DSL format
Architectural Overview
W rkflow
tikal@cws2:~/chef-repo$

knife cookbook create ntp
** Creating cookbook ntp
** Creating README for cookbook: ntp
** Creating CHANGELOG for cookbook: ntp
** Creating metadata for cookbook: ntp
Write the recipe
{
{

Configure Knife [ workstation ]
Setup SCM
Define environment
Bootstrap node => affiliate to environment
cookbook (clone/myown) => server
Role<= recipes + attributes => server
node<= role
Wait for chef-client run
Push to SCM
knife configure -i
git clone ... [chef-repo]
knife environment from file envname.json
knife cookbook site download "kookbook name"
knife role from file base.json
Upload recipe to chef server [knife cookbook upload ...]
knife bootstrap -x user -P passwd -r "role[rolename]"
knife node edit nodename (add recipe)
Push to SCM
Wait for chef-client to run
}
Our Actions thought this introduction
Roles
True story:
We used sudo cookbook
https://github.com/opscode/cookbooks/tree/master/sudo
Sudo cookbook defines users in /etc/sudoers file ...
After chef run we got locked out of the system
Roles are a way to group recipes for
re-use / share between nodes
Offline (SCM) way to store
configuration and share
A mechanism for managing different groups of nodes with specific environmental attributes [and runlists]
Create a role with knife
tikal@cws:~$
knife role list
base
demo
onemin
list existing roles
tikal@cws:~$
knife role create demorole
will return:
tikal@cws:~$ knife role from file \
~/chef-repo/roles/rolename.json
or rolename.erb [dsl format]
Do the same but from
file (in SCM)
role nesting
role nesting
Role "onemin"* includes all the
attributes & recipes
from "base", and will override the
attribute
chef_client: interval
*onemin is named after "run chef-client every minute which with time became 30 seconds...
Using search
knife search node ip*:'172.20.20.21'*
-Fj
Use -Fj and you will get all the output + ohai properties of that node !
Search for all nodes with IP 172.20.20.21[10-55]
Search for all centos nodes
tikal@cws:~$

knife node edit n2e2.milkyway.local
Add role(s) to node
As a sysadmin
We keep hacking systems
Relaying on memory
No SCM / traceability
Repeating our selves
A little Deeper
The Problem with this recipe
ntp server address is "hard coded"
only one server !
"ntpd" is correct only on
fedora/redhat/centos etc
Attributes to the rescue ...
Template file needs to support:
Our "servers" Array
Flexible Service name
add a new file
cookbooks/ntp/attributes/default.rb
Create a servers array with default values
Determine service name according to OS
Before:
After:
evaluated to "
time.nist.gov
"
For each ntp server in:
Or
which will set your own ntp servers
defined in:
cookbooks/ntp/attributes/default.rb
Update recipe
In ubu
n
tu & c
e
ntos case package name is
ntp
The service name will be evaluated by chef in attributes file (appended to the node attributes at run time )
Apply recipe to your role (we did previously in role "base")
Update cookbook version [
edit metadata.rb
]
Upload recipe to chef server [
knife cookbook upload ntp
]
Test this recipe on centos + ubuntu ...
For very
basic & manual
testing : use
knife search
...
Test the recipe !
Available @:
https://github.com/tikalk/chef-intro-repo
This is just an example there is a more extensive ntp cookbook !!!
https://github.com/opscode/cookbooks/tree/master/ntp
Improve your recipe(s)
service name
"
ntp
" - ubu
n
tu
"
ntpd
" - centos
What's in A Chef
Start
A Chef Run
Building the node object
Ohai OS attribute discovery
Previous run data collection from
server
[unless
runnin
g solo]
Any JSON Attributes or Recipes
All the Ohai attributes
Chef Server Registration / Authentication
If exists :: /etc/chef/client.pem validated against server
If not :: validation.pem is used to register the node and store private key in /etc/chef/client.pem
Build , Register / Authenticate
Synchronize Cookbooks
Server Cookbooks => /var/chef/cache/cookbooks/
Important note!
Chef will not start executing unless the entire cookbook(s), Extract all Libraries, Attributes, Definitions and Recipes from these cookbooks.
This assures that a chef-client will not "get stuck" whilst applying configuration.
Load Libraries
from all cookbooks, making any language extensions or ruby classes available.
Load Attributes
from all Attribute files => update Node attributes and Recipes.
Load Definitions
Definitions must be loaded before Recipes, since they create new pseudo-Resources.

Load Recipes
At this point, the Recipes themselves are evaluated. We are not taking any action on the resources in the recipes at this stage - we are taking each evaluated resource and putting it in the Resource Collection.

This is essentially an Array of each evaluated resource, along with some helpful functions.
Plain Ruby code outside of resources is evaluated, however.
If you would like Ruby code executed with other resources, use a Ruby Block Resource.
You can have Chef Evaluate and Run Resources at Compile Time, too.
"Compile"
Compile
What ?
Install applications
Define services
Start / Stop services
Configure / Auto configure
servers and services
Share configurations among servers / the global community
Anything else .... you might need to run
What does chef do ?
Hosted
That's not all ....
Private
OS Server
Client
Solo
Shef
Chef
workstation
Environments
Nodes
Cookbooks
Recipes
Files / Templates
Attributes
Data Bags
Search
...
...
11.2.2013
16.1.2013
Notify
Full transcript