SlideShare ist ein Scribd-Unternehmen logo
1 von 236
Downloaden Sie, um offline zu lesen
Tech Superwomen Summit - v 1.0.0
Introduction to Chef
training@getchef.com
Copyright (C) 2015 Chef Software, Inc.
1
Pre-Requisites
• Laptop with an SSH client
• Basic Unix command line knowledge
• Wireless: UCSFguest
2
AWS PopUp Loft - A Taste of Chef v2.0.0
Introductions
3
Course Instructor
4
Jennifer Davis
Solutions Engineer
Email:sigje@chef.io Twitter: @sigje
Communicate and Collaborate
• Hashtags: #TSWS15 #getchef
5
Instructor Introduction
• Name: Franklin Webber
• Current job role: Developer / Instructor
• Previous job roles/background: ARMY SGT, QA,
SDET
• Experience with Chef/Config Management:
Deployments with Ruby on Rails Applications
• Favorite Text Editor: Sublime Text
6
Introduce Yourselves
• Name
• Current job role
• Previous job roles/background
• Experience with infrastructure/automation
• Experience with Chef and/or config management
7
AWS PopUp Loft - A Taste of Chef v2.0.0
Course Objectives and Style
8
Course Objectives
• Upon completion of this course you will be able to
• Automate common infrastructure tasks with Chef
• Describe some of Chef’s tools
• Apply Chef’s primitives to solve your problems
• Know where to go for more info
9
Learning Chef
• You bring domain expertise about your business and
problems to solve.
• Chef provides a framework to solve problems.
• Together, we work together to help you express
solutions to your problems with Chef.
10
Chef is a Language
• Learning Chef is like learning the basics of a
language
• 80% fluency reached quickly
• The remaining 20% just takes practice
• The best way to learn Chef is to use Chef
11
Training is a discussion
• Lots of hands on labs
• Lots of typing
• Ask questions when they come to you
• Ask for help when you need it
• Help each other
• We will troubleshoot issues on the spot
12
Just an Introduction
• This course is an introduction to using Chef to
manage your infrastructure.
• We cover a lot of material!
• Any discussion items that are too far off topic will be
captured
• We'll return to these items as time permits
13
Setting Expectations
• Experience Level: Beginner
• Flexible content based on class
• It’s ok to leave (and come back).
14
AWS PopUp Loft - A Taste of Chef v2.0.0
Agenda
15
Topics
• Introduction to Infrastructure Automation
• Overview of Chef
• Workstation Setup
• Resources
• Describing Policies
• Wrap Up
16
Breaks!
• We’ll take a break as often as we need them.
• We’ll take a break for lunch.
17
AWS PopUp Loft - A Taste of Chef v2.0.0
Legend
18
$ ifconfig
Legend: Example Terminal Command and Output
lo0:
flags=8049<UP,LOOPBACK,RUNNING,MULTICA
ST> mtu 16384!
!options=3<RXCSUM,TXCSUM>!
!inet6 fe80::1%lo0 prefixlen 64
scopeid 0x1!
!inet 127.0.0.1 netmask 0xff000000!
19
OPEN IN EDITOR:
SAVE FILE!
~/hello_world
Hi!!
!
I am a friendly file.
Legend: Example of editing a file on your workstation
20
AWS PopUp Loft - A Taste of Chef v2.0.0
Infrastructure Automation
21
What is Infrastructure Automation?
22
What is infrastructure?
23
Applications
• MongoDB
• Apache
• Java
• Drupal
• WordPress
• cakephp
24
Applications - Complexity
•Single service == multiple
applications.
•Single application == a
component of service.
25
Configurations
• Operating Systems
• Software
• Network
• Storage
26
Configurations - Complexity
•Multiple services using
same software with
different configurations.
•Different Operating
Systems requiring same
software (and user
experience).
27
Access Control
• Users
• Groups
• Organizations
28
Access Control - Complexity
•Different users access to
different systems.
•External versus internal.
•Compliance.
29
Data
• Tweets
• Profiles
• Emails


Specific to your organization.
30
Servers
• physical hardware
• cloud services
• virtual
31
Servers - Complexity
•Specialization in
hardware.
•Lack of standardization.
32
Network & Storage
• routers
• switches
• firewalls
• tape libraries
• NAS/SAN attached storage
33
People
34
What is automation?
35
Automaton
• acting of one’s own will.
36
Automation
• reducing labor, energy, and materials
• improve quality, precision, accuracy
37
What is infrastructure automation?
38
Infrastructure Automation is
creating control systems that reduce
the burden on people to manage
services and increase the quality,
accuracy and precision of a service
to the consumers of the service.
39
AWS PopUp Loft - A Taste of Chef v2.0.0
Overview of Chef
40
Benefits of Automation
41
Dimensions of Scale
42
Automation Platform
• Dependable view of your network’s state.
• Handles complex dependencies among nodes.
• Fault tolerant.
• Secure.
• Multi-platform.
• Supports multiple compute platforms.
• Foundation for innovation.
43
Infrastructure as Code
• Programmatically
provision and
configure
components.
44
Infrastructure as Code
• Treat like any code
base.
45
Infrastructure as Code
• Reconstruct business
from code repository,
data backup, and
compute resources.
46
Infrastructure as Code
• Programmatically
provision and
configure components.
• Treat like any other
code base.
• Reconstruct business
from code repository,
data backup, and
compute resources.
47
Policy-based Management
• You capture the policy for your infrastructure in code.
• Chef ensures each node in your infrastructure
complies with the policy.
48
Policy-based Management
• Chef provides a domain-specific language (DSL) that
allows you to specify policy for your infrastructure
• Policy describes the desired state
• Policies can be statically or dynamically defined.
49
Chef Components
50
Chef Server Functions
51
AWS PopUp Loft - A Taste of Chef v2.0.0
Workstation Setup
Getting Started
52
Pre-Configured Workstation
• http://bit.ly/15NJUR0
• chef-dk installed via:
• curl -L https://www.getchef.com/chef/install.sh |
sudo bash -s -- -P chefdk
53
Chef Development Kit
• Contains everything you need to start using Chef
• The new “chef” tool
• Chef-client distribution
• Testing frameworks
• Linting tools
• https://downloads.chef.io/chef-dk/
54
SSH to your instance
• Login: chef
• Password: chef
!
• ssh root@IPADDRESS
55
$ touch NAME_INTRO; ls | grep INTRO
Verify your node
jenniferdavis_INTRO
56
$ chef verify
Verify your chef installation
Running verification for component 'berkshelf'!
Running verification for component 'test-kitchen'!
Running verification for component 'chef-client'!
Running verification for component 'chef-dk'!
Running verification for component 'chefspec'!
Running verification for component 'rubocop'!
Running verification for component 'fauxhai'!
Running verification for component 'knife-spork'!
Running verification for component 'kitchen-vagrant'!
Running verification for component 'package installation'
57
AWS PopUp Loft - A Taste of Chef v2.0.0
Resources
58
Fundamental Building Blocks
What is infrastructure?
59
Infrastructure Elements
• the individual components or building blocks we
have access to automate.
60
Infrastructure Elements
files
directories
symlinks
mounts
users
groups
software packages
external services
filesystems
61
Resources
• A resource represents an element or component of
the system and the desired state of that element.
62
package "haproxy" do!
action :install!
end
Resources - Package
• Package that should
be installed
63
service "iptables" do!
action [ :start, :enable ]!
end
Resources - Service
• Service that should be
running and enabled
to start on reboot
64
cron "restart webserver" do!
hour "2"!
minute "0"!
command "service httpd restart"!
end
Resources - Cron
• Cron job that should
be configured
65
user "nginx" do!
comment "nginx user" !
uid "500" !
gid "500"!
supports :manage_home => true !
end
Resources - User
• User that should be
managed
66
dsc_script "emacs" do!
code <<-EOH!
Environment 'texteditor'!
{!
Name = 'EDITOR'!
Value = 'c:emacsbinemacs.exe'!
}!
EOH!
end
Resources - DSC
• A Desired State
Configuration setting
that should be applied
67
registry_key “HKEY_LOCAL_MACHINE
SOFTWAREMicrosoftWindows
CurrentVersionPolicies
System” do!
values [{!
:name => "Enable LUA”,!
:type => :dword,!
:data => 0!
}]!
end!
Resources - Registry Key
• Registry Key that
should be created
68
package "haproxy" do!
action :install!
end
Resources - Package
• Package that should
be installed
69
Resources
• A resource represents an element or component of
the system and the desired state of that element.
• https://docs.chef.io/chef/resources.html
70
Lab 1 - Install a text editor
• Problem: Our workstation does not have $EDITOR
installed
!
• Success Criteria: You can edit files with $EDITOR
!
• $EDITOR is your favorite command line text editor:
vim, emacs, or nano
71
$ ssh chef@IPADDRESS
SSH to your workstation
chef@54.88.161.76's password:
Last login: Fri Jan 30 06:18:29 2015 from 12.232.194.107
72
$ which vim
Is $EDITOR installed?
[chef@ip-172-31-35-99 ~]$ which vim
/usr/bin/vim
73
$ which nano
Is $EDITOR installed?
[chef@ip-172-31-35-99 ~]$ which nano
/usr/bin/which: no nano in (/usr/local/bin:/
bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/
home/chef/bin)
74
chef-apply
• chef-apply is an executable program that allows you
to work with resources
• Is included as a part of the ChefDK
• A great way to explore resources
• NOT how you will eventually use Chef in production
75
$ chef-apply --help
What does chef-apply do?
Usage: chef-apply [RECIPE_FILE] [-e RECIPE_TEXT] [-s]
--[no-]color Use colored output, defaults to enabled
-e, --execute RECIPE_TEXT Execute resources supplied in a string
-l, --log_level LEVEL Set the log level (debug, info, warn,
error, fatal)
-s, --stdin Execute resources read from STDIN
-v, --version Show chef version
-W, --why-run Enable whyrun mode
-h, --help Show this message
76
$ chef-apply -e "package 'vim'"
Install vim
[chef@ip-172-31-35-99 ~]$ chef-apply -e "package 'vim'"
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* package[vim] action install (up to date)
77
$ chef-apply -e "package 'emacs'"
Install emacs
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* package[emacs] action install
- install version 23.1-25.el6 of package emacs
78
$ sudo chef-apply -e "package 'nano'"
Install nano
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* package[nano] action install
- install version 2.0.9-7.el6 of package nano
79
Resources
• Describe the desired state
• Do not need to tell Chef how to get there
!
• What happens if you re-run the chef-apply
command?
80
$ chef-apply -e "package 'vim'"
Install vim
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* package[vim] action install (up to date)
81
package "vim"
Test and Repair
• Resources follow a
test and repair model
82
package "vim"
Test and Repair
• Resources follow a
test and repair model
83
Is vim installed?Test
package "vim"
Test and Repair
• Resources follow a
test and repair model
84
Is vim installed?
Yes
Test
package "vim"
Test and Repair
• Resources follow a
test and repair model
85
Is vim installed?
Yes
Done
Test
package "vim"
Test and Repair
• Resources follow a
test and repair model
86
Is vim installed?
Yes No
Done
Test
package "vim"
Test and Repair
• Resources follow a
test and repair model
87
Is vim installed?
Yes No
Install itDone
Test
package "vim"
Test and Repair
• Resources follow a
test and repair model
88
Is vim installed?
Yes No
Install itDone
Test
Repair
Resources: Test and Repair
• Resources follow a test & repair model
!
• Resource currently in the desired state? (test)
• Yes - Do nothing
• No - Bring the resource into the desired state
(repair)
89
• dsc_script
• registry_key
• powershell_script
• cron
• mount
• route
• … and more!
Resources
• package
• template
• service
• directory
• user
• group
90
Lab 2 - Hello World!
• Problem: Oops, we forgot to start with “hello world”
!
• Success Criteria: A file with “Hello, World!” content
is available in our home directory
91
Recipe
• A recipe is an ordered list of resources.
• Chef DSL is ruby.
• Recipe stored in file with .rb extension.
92
SAVE FILE!
file "hello.txt" do!
action :create!
content "Hello, World!"!
mode "0644"!
owner "root"!
group "root"!
end
Hello, World!
OPEN IN EDITOR: ~/hello.rb
93
Review
• hello.rb - recipe we
created.
• hello.txt - the file we
want to manage
through file resource.
94
hello.rb hello.txt
Recipe File
Hello, world!
$ sudo chef-apply hello.rb
Apply hello.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)!
* file[hello.txt] action create!
- create new file hello.txt!
- update content in file hello.txt from none to dffd60!
--- hello.txt! 2015-01-11 08:36:50.195712169 +0000!
+++ /tmp/.hello.txt20150111-5823-4tggr4!2015-01-11 08:36:50.196712169 +0000!
@@ -1 +1,2 @@!
+Hello, World!!
- change mode from '' to '0644'!
- change owner from '' to 'root'!
- change group from '' to 'root'!
- restore selinux security context
95
$ cat hello.txt
Read hello.txt
Hello, World!
96
file "hello.txt"
Chef Resources
• Have a type
97
file "hello.txt"
Chef Resources
• Have a type
• Have a name
98
file "hello.txt" do!
!
!
end
Chef Resources
• Have a type
• Have a name
• Include details
between keywords do
and end
99
file "hello.txt" do!
action :create!
end
Chef Resources
• Have a type
• Have a name
• Include details
between keywords do
and end
• Describe the state
using keyword
action
100
file "hello.txt" do!
action :create!
end
Chef Resources — In Plain English
• The TYPE named
NAME should be
ACTION’ed
!
• The file named
“hello.txt” should be
created
101
file "hello.txt" do!
action :create!
content "Hello, World!"!
mode "0644"!
owner "root"!
group "root"!
end
Chef Resources
• Have a type
• Have a name
• Include details between
keywords do and end
• Describe the state
using keyword action
• Include additional
details about the state
of the thing (attributes)
102
file "hello.txt" do!
action :create!
content "Hello, World!"!
mode "0644"!
owner "root"!
group "root"!
end
• The TYPE named
NAME should be
ACTION’ed with
ATTRIBUTES
103
Chef Resources — In Plain English
file "hello.txt" do!
action :create!
content "Hello, World!"!
mode "0644"!
owner "root"!
group "root"!
end
• The file named
“hello.txt” should be
created with content of
“Hello, World!”,
permissions of 0644,
owned by the be root
user and root group
104
Chef Resources — In Plain English
$ chef-apply hello.rb
Re-apply hello.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)!
* file[hello.txt] action create (up to date)
105
Resources: Test and Repair
• Resources follow a test & repair model
!
• Resource currently in the desired state? (test)
• Yes - Do nothing
• No - Bring the resource into the desired state
(repair)
106
What if…?
• Change the content of the file using your favorite text
editor?
• Change the ownership of the file?
• Delete the file?
107
Let’s look at the File Resource
• http://docs.chef.io/chef/resources.html#file
108
Lab 2 - Hello World!
• Problem: Clean up “Hello World” file.
!
• Success Criteria: Deletion of hello.txt file.
109
Lab 2 - Hello World!
• We will create a new recipe called goodbye.
• Where will this be saved?
• What type of resource will we use?
• What is the name of the resource?
• What action?
110
SAVE FILE!
file "hello.txt" do!
action :delete!
end
Goodbye Hello, World!
OPEN IN EDITOR: ~/goodbye.rb
111
$ chef-apply goodbye.rb
Apply goodbye.rb
112
• dsc_script
• registry_key
• powershell_script
• cron
• mount
• route
Resources
• package
• template
• service
• directory
• user
• group
113
Resources
• What states can a file be in?
• What state will a file be in if you don’t declare an
action?
• What state will a package be in if you don’t declare
an action?
• Do you have to indent the attributes of a resource?
• What Chef tool allows us to easily explore
resources?
114
Lab 3 - Manage a file
• Problem: We want users logging into the system to
see “Property of COMPANY NAME” upon login.
• Success Criteria: An updated /etc/motd with
“Property of COMPANY NAME” that is displayed on
login.
115
Lab 3 - Manage a file
• The file named /etc/motd should have the contents
“Property of COMPANY NAMEn”, permissions of
“0644”, and owned by the group and user named
“root”
116
Summary
• What questions can I answer for you?
117
AWS PopUp Loft - A Taste of Chef v2.0.0
Describing Policies
118
Recipes & Cookbooks
Resources > Recipes > Cookbooks
• A resource is a piece of the system and its desired
state
• A recipe is a collection of resources
• A cookbook is a collection of recipes
• Cookbooks can also contain ingredients
• A cookbook is a “package” of policy information
119
Recipe - A collection of resources
120
package "haproxy" do!
action :install!
end!
!
template "/etc/haproxy/haproxy.cfg" do!
source "haproxy.cfg.erb"!
owner "root"!
group "root"!
mode "0644"!
notifies :restart, "service[haproxy]"!
end!
!
service "haproxy" do!
supports :restart => :true!
action [:enable, :start]!
end
• Body Level One
• Body Level Two
• Body Level Three
• Body Level Four
• Body Level Five
Order Matters
package "haproxy" do!
action :install!
end!
!
template "/etc/haproxy/haproxy.cfg" do!
source "haproxy.cfg.erb"!
owner "root"!
group "root"!
mode "0644"!
notifies :restart, "service[haproxy]"!
end!
!
service "haproxy" do!
supports :restart => :true!
action [:enable, :start]!
end
• Resources are
executed in order
1st
121
• Body Level One
• Body Level Two
• Body Level Three
• Body Level Four
• Body Level Five
Order Matters
package "haproxy" do!
action :install!
end!
!
template "/etc/haproxy/haproxy.cfg" do!
source "haproxy.cfg.erb"!
owner "root"!
group "root"!
mode "0644"!
notifies :restart, "service[haproxy]"!
end!
!
service "haproxy" do!
supports :restart => :true!
action [:enable, :start]!
end
• Resources are
executed in order
1st
2nd
122
• Body Level One
• Body Level Two
• Body Level Three
• Body Level Four
• Body Level Five
Order Matters
package "haproxy" do!
action :install!
end!
!
template "/etc/haproxy/haproxy.cfg" do!
source "haproxy.cfg.erb"!
owner "root"!
group "root"!
mode "0644"!
notifies :restart, "service[haproxy]"!
end!
!
service "haproxy" do!
supports :restart => :true!
action [:enable, :start]!
end
• Resources are
executed in order
1st
2nd
3rd
123
Cookbook
• A “package” for Chef policies
• Typically map 1:1 to a piece of software or
functionality
• Distribution unit
• Versioned
• Modular and re-usable
124
Abstracting Data from Policy
• Policy - The desired state of the system.
• Data - The details that might change.
125
Abstracting Data from Policy
• Policy - Tomcat should be installed
• Data - It should be version 6 and listening on 8080
126
Abstracting Data from Policy
• Policy - A file should exist
• Data - The content of that file
127
Lab 4 - Manage Data & Policy Separately
• Problem: The policy for managing file/etc/motd
currently has state intermingled with content
!
• Success Criteria: We have a policy that manages
the state and content of /etc/motd separately
128
file "/etc/motd" do!
content "Property of COMPANY NAME" !
action :create!
mode "0644" !
owner "root" !
group "root"!
end
Message of the day
• State — policy that
describes the
resource
129
file "/etc/motd" do!
content "Property of COMPANY NAME" !
action :create!
mode "0644" !
owner "root" !
group "root"!
end
Message of the day
• Content — data that
may change
independently of
policy changes
130
Cookbooks contain ingredients
• Cookbooks allow you to package up separate
components in one distributable unit
• Cookbooks contain recipes (policy)
• Cookbooks can also contain files to distribute
(content)
131
Lab 4 - Manage Data & Policy Separately
• Required steps:
• Create a repository to store our cookbooks
• Create a cookbook
• Separate policy from data
132
The chef-repo
• Chef cookbooks should be stored in a version
control system
• You have options for how best to manage your
repository of chef code
• We will create a single chef-repo for all of our
cookbooks
133
The “chef” command
• chef is an executable command line tool for
• generating cookbooks, recipes, and other things
that make up your Chef code
• ensuring RubyGems are downloaded properly for
your development environment
• verifying that all the Chef components are installed
and configured correctly
• Included with ChefDK
134
$ chef generate --help
Usage: chef generate GENERATOR [options]!
!
Available generators:!
app Generate an application repo!
cookbook Generate a single cookbook!
recipe Generate a new recipe!
attribute Generate an attributes file!
template Generate a file template!
file Generate a cookbook file!
lwrp Generate a lightweight resource/provider!
repo Generate a Chef policy repository!
policyfile Generate a Policyfile for use with the install/push commands
(experimental)
135
What can “chef” generate?
$ chef generate repo --help
Usage: chef generate repo NAME [options]!
-C, --copyright COPYRIGHT Name of the copyright holder - defaults to 'The Authors'!
-m, --email EMAIL Email address of the author - defaults to 'you@example.com'!
-a, --generator-arg KEY=VALUE Use to set arbitrary attribute KEY to VALUE in the
code_generator cookbook!
-I, --license LICENSE all_rights, apache2, mit, gplv2, gplv3 - defaults to all_rights!
-p, --policy-only Create a repository for policy only, not cookbooks!
-g GENERATOR_COOKBOOK_PATH, Use GENERATOR_COOKBOOK_PATH for the code_generator cookbook!
--generator-cookbook
136
How do we generate a repo?
$ cd ~
137
Start from home directory
$ chef generate repo chef-repo
Compiling Cookbooks...!
Recipe: code_generator::repo!
* directory[/root/chef-repo] action create!
- create new directory /root/chef-repo!
- restore selinux security context!
* template[/root/chef-repo/LICENSE] action create!
- create new file /root/chef-repo/LICENSE!
- update content in file /root/chef-repo/LICENSE from none to aed48c!
(diff output suppressed by config)!
- restore selinux security context!
* cookbook_file[/root/chef-repo/README.md] action create!
- create new file /root/chef-repo/README.md!
- update content in file /root/chef-repo/README.md from none to 767ead!
(diff output suppressed by config)!
- restore selinux security context!
* cookbook_file[/root/chef-repo/Rakefile] action create!
- create new file /root/chef-repo/Rakefile!
- update content in file /root/chef-repo/Rakefile from none to 108932!
(diff output suppressed by config)!
- restore selinux security context
138
Make a chef repo
$ tree
!"" chef-repo!
#"" certificates!
$   !"" README.md!
#"" chefignore!
#"" config!
$   !"" rake.rb!
#"" cookbooks!
$   !"" README.md!
#"" data_bags!
$   !"" README.md!
#"" environments!
$   !"" README.md!
#"" LICENSE!
#"" Rakefile!
#"" README.md!
!"" roles!
!"" README.md
139
Examine chef-repo
Lab 4 - Manage Data & Policy Separately
• Required steps:
✔️ Create a repository to store our cookbooks
• Create a cookbook
• Separate policy from data
140
$ chef generate cookbook --help
Usage: chef generate cookbook NAME [options]!
-C, --copyright COPYRIGHT Name of the copyright holder - defaults to 'The Authors'!
-m, --email EMAIL Email address of the author - defaults to 'you@example.com'!
-a, --generator-arg KEY=VALUE Use to set arbitrary attribute KEY to VALUE in the
code_generator cookbook!
-I, --license LICENSE all_rights, apache2, mit, gplv2, gplv3 - defaults to all_rights!
-g GENERATOR_COOKBOOK_PATH, Use GENERATOR_COOKBOOK_PATH for the code_generator cookbook!
--generator-cookbook
141
How do we generate a cookbook?
$ chef generate cookbook cookbooks/motd
Compiling Cookbooks...!
Recipe: code_generator::cookbook!
* directory[/tmp/chef-repo/cookbooks/motd] action create!
- create new directory /tmp/chef-repo/cookbooks/motd!
* template[/tmp/chef-repo/cookbooks/motd/metadata.rb] action create_if_missing!
- create new file /tmp/chef-repo/cookbooks/motd/metadata.rb!
- update content in file /tmp/chef-repo/cookbooks/motd/metadata.rb from none to 811b2e!
(diff output suppressed by config)!
* template[/tmp/chef-repo/cookbooks/motd/README.md] action create_if_missing!
- create new file /tmp/chef-repo/cookbooks/motd/README.md!
- update content in file /tmp/chef-repo/cookbooks/motd/README.md from none to 918996
142
Generate a “motd” cookbook
$ tree
#"" cookbooks!
$   #"" motd!
$   $   #"" Berksfile!
$   $   #"" chefignore!
$   $   #"" metadata.rb!
$   $   #"" README.md
143
Examine motd cookbook
Lab 4 - Manage Data & Policy Separately
• Required steps:
✔️ Create a repository to store our cookbooks
✔️ Create a cookbook
• Separate policy from data
144
$ cat ~/motd.rb >> ~/chef-repo/cookbooks/motd/recipes/default.rb
145
Copy your motd.rb
OPEN IN EDITOR: ~/chef-repo/cookbooks/motd/recipes/default.rb
#!
# Cookbook Name:: motd!
# Recipe:: default!
#!
# Copyright (c) 2015 The Authors, All Rights Reserved.!
file "/etc/motd" do!
content "Property of COMPANY NAMEn” !
action :create!
mode "0644" !
owner "root" !
group "root"!
end
Update the recipe
146
Which resource should we use?
• cookbook_file
• file
• remote_file
• template
147
motd/!
#"" Berksfile!
#"" chefignore!
#"" files!
$   !"" default!
$   !"" motd!
#"" metadata.rb!
#"" README.md!
!"" recipes!
!"" default.rb
cookbook_file
• A file stored in the
cookbook contains the
content of the file
148
file "/etc/motd" do!
content "Property of COMPANY NAME" !
action :create!
mode "0644" !
owner "root" !
group "root"!
end
file
• The content is
described inline in
the recipe
149
remote_file "/etc/motd" do!
source "http://bit.ly/motd"!
action :create!
mode "0644" !
owner "root" !
group "root"!
end
remote_file
150
• The file is stored in a
remote location, such
as on a webserver
motd!
#"" Berksfile!
#"" chefignore!
#"" metadata.rb!
#"" README.md!
#"" recipes!
$   !"" default.rb!
!"" templates!
!"" default!
!"" motd.erb
template
• A template in the
cookbook is used to
render the content of
the file
151
motd/templates/default/motd.erb!
template
• A template is a mix of
static and dynamic
content
152
Property of <%= @company_name %>!
Which resource should we use?
• cookbook_file - static file within the cookbook
• file - content managed inline
• remote_file - static file obtained from URL
• template - dynamic content rendered from ERB
153
template
• An ERB template stored as part of our cookbook
154
OPEN IN EDITOR: ~/chef-repo/cookbooks/motd/recipes/default.rb
#!
# Cookbook Name:: motd!
# Recipe:: default!
#!
# Copyright (c) 2015 The Authors, All Rights Reserved.!
template "/etc/motd" do!
source "motd.erb" !
action :create!
mode "0644" !
owner "root" !
group "root"!
end
Update the recipe
155
$ chef generate template --help
Usage: chef generate template [path/to/cookbook] NAME [options]!
-C, --copyright COPYRIGHT Name of the copyright holder - defaults to 'The Authors'!
-m, --email EMAIL Email address of the author - defaults to 'you@example.com'!
-a, --generator-arg KEY=VALUE Use to set arbitrary attribute KEY to VALUE in the
code_generator cookbook!
-I, --license LICENSE all_rights, apache2, mit, gplv2, gplv3 - defaults to all_rights!
-s, --source SOURCE_FILE Copy content from SOURCE_FILE!
-g GENERATOR_COOKBOOK_PATH, Use GENERATOR_COOKBOOK_PATH for the code_generator cookbook!
--generator-cookbook
156
How do we generate a template?
$ cd ~/chef-repo!
$ chef generate template cookbooks/motd motd -s /etc/motd
Compiling Cookbooks...!
Recipe: code_generator::template!
* directory[cookbooks/motd/templates/default] action create!
- create new directory cookbooks/motd/templates/default!
* file[cookbooks/motd/templates/default/motd.erb] action create!
- create new file cookbooks/motd/templates/default/motd.erb!
- update content in file cookbooks/motd/templates/default/motd.erb from none to 166ed9!
(diff output suppressed by config)
157
Create the ERB template
$ tree
$   $   #"" templates!
$   $   $   !"" default!
$   $   $   !"" motd.erb
158
Examine cookbook
OPEN IN EDITOR: ~/chef-repo/cookbooks/motd/templates/default/motd.erb
Property of COMPANY NAME
Check the template
159
chef-apply
• chef-apply does not understand cookbooks, only
resources and recipes
• We cannot use chef-apply to apply the policy stored
in our motd cookbook
160
chef-client
• chef-client is an executable
• performs all actions required to bring a node into
the desired state
• typically runs on a regular basis
• daemon
• cron
• Windows service
• Included with ChefDK
161
chef-client applying policies
162
chef-client applying policies
163
chef-client
chef-client applying policies
164
chef-client
What policy should I follow?
chef-client applying policies
165
chef-client
What policy should I follow?
Test & Repair
Apply the policy
chef-client applying policies
166
chef-client
What policy should I follow?
Test & Repair
Apply the policy
chef-client applying policies
167
chef-client
What policy should I follow?
Test & Repair
Apply the policy
chef-client
chef-client applying policies
168
chef-client
What policy should I follow?
Test & Repair
Apply the policy
chef-client
What policy should I follow?
chef-client applying policies
169
chef-client
What policy should I follow?
Test & Repair
Apply the policy
chef-client
What policy should I follow?
Test & Repair
Apply the policy
chef-client modes
• In conjunction with a Chef Server
• Local mode (no Chef Server)
170
chef-client privileges
• Usually run with elevated privileges
• root
• sudo
• Administrator
• Can run as non-privileged user
171
$ cd ~/chef-repo!
$ chef-client --local-mode -r “recipe[motd::default]”!
$ chef-client --local-mode -r “recipe[motd]”!
$ chef-client --local-mode -r “recipe[motd::weather]"
2015-01-11T11:05:00+00:00] WARN: No config file found or specified on command line, using command
line options.!
Starting Chef Client, version 11.18.0.rc.1!
resolving cookbooks for run list: ["motd"]!
Synchronizing Cookbooks:!
- motd!
Compiling Cookbooks...!
Converging 0 resources!
!
Running handlers:!
Running handlers complete!
Chef Client finished, 0/0 resources updated in 3.99531239 seconds
172
Apply our recipe using chef-client
Pop Quiz
• Why did chef-client update zero resources?
173
Pop Quiz
• Why did chef-client update zero resources?
!
• Resources test & repair
• Remember: we generated the template from an
existing file on the filesystem
• The content of /etc/motd is already the content we
wanted
174
chef-client applying policies
recipe[motd]
175
chef-client
What policy should I follow?
Test & Repair
Apply the policy
recipe[motd]
Lab 4 - Manage Data & Policy Separately
• Required steps:
✔️ Create a repository to store our cookbooks
✔️ Create a cookbook
✔️ Separate policy from data
176
Separating data from policy
• Storing file content directly in a recipe is not typically
the best choice
• We can manage that content separately using a
different resource
• cookbook_file
• remote_file
• template
177
Template resources
• An ERB template that generates files based on a
mix of static content along with variables and logic to
determine dynamic content
• If in doubt, start with a template
178
What if…?
• The contents of the motd file should be pulled from a
file in an S3 bucket?
• The motd file should have variable content based on
different owners using the same cookbook?
179
Summary
• What components can be in a cookbook?
• What program should we use to apply code from
cookbooks?
• What resource should we look to first when
managing a file?
180
Summary
• What questions can I answer for you?
181
AWS PopUp Loft - A Taste of Chef v2.0.0
Creating a simple web server
182
An Example Policy
Lab 5 - Install an Apache webserver
• The Problem: We need a web server configured to
serve up a custom home page
!
• Success Criteria: We can see the custom
homepage in a web browser
183
Required steps
• Install Apache
• Write out the home page
• Start the Apache service
• Make sure the Apache service starts when the machine
boots
• Stop and disable the iptables service
!
• Please note we're teaching Chef primitives, not web server management!
This is probably not the Apache HTTP server configuration you would use in
production.
184
$ cd ~/chef-repo!
$ chef generate cookbook cookbooks/webserver
Create a new webserver cookbook
Compiling Cookbooks...!
Recipe: code_generator::cookbook!
* directory[/root/chef-repo/webserver] action create!
- create new directory /root/chef-repo/webserver!
- restore selinux security context!
* template[/root/chef-repo/webserver/metadata.rb] action create_if_missing!
- create new file /root/chef-repo/webserver/metadata.rb!
- update content in file /root/chef-repo/webserver/metadata.rb from none to 4c0e2d!
(diff output suppressed by config)!
- restore selinux security context!
* template[/root/chef-repo/webserver/README.md] action create_if_missing!
- create new file /root/chef-repo/webserver/README.md!
- update content in file /root/chef-repo/webserver/README.md from none to 5c3d3a!
(diff output suppressed by config)!
- restore selinux security context!
* cookbook_file[/root/chef-repo/webserver/chefignore] action create!
- create new file /root/chef-repo/webserver/chefignore!
- update content in file /root/chef-repo/webserver/chefignore from none to 9727b1!
(diff output suppressed by config)!
- restore selinux security context
185
OPEN IN EDITOR: ~/chef-repo/cookbooks/webserver/recipes/default.rb
#!
# Cookbook Name:: webserver!
# Recipe:: default!
#!
# Copyright (c) 2015 The Authors, All Rights Reserved.
Exercise: Edit the default recipe
186
Which resource should we use?
• Install Apache
• Write out the home page
• Start the Apache service
• Make sure the Apache service starts when the machine boots
• Stop and disable the iptables service
187
Which resource should we use?
• Install Apache
• Write out the home page
• Start the Apache service
• Make sure the Apache service starts when the machine boots
• Stop and disable the iptables service
188
3 most common resources - PST
• Install software (package)
• Manipulate files (template)
• Manipulate services (service)
!
• You will see this pattern very often
189
• Install Apache - the package is named “httpd”
• Write out the home page - /var/www/html/index.html
• Manage the apache service - named “httpd”
• Make sure the service is started
• Make sure the service is enabled to start on boot
• Manage the iptables service - named “iptables”
• Make sure the service is stopped
• Make sure the service is disabled to start on boot
!
190
Lab 5 - Install an Apache webserver
#!
# Cookbook Name:: webserver!
# Recipe:: default!
#!
# Copyright (c) 2015 The Authors, All Rights Reserved.!
!
package "httpd"!
!
service "httpd" do!
action [ :enable, :start ]!
end!
!
template "/var/www/html/index.html" do!
source "index.html.erb"!
end!
!
service "iptables" do!
action [ :disable, :stop ]!
end
Checkpoint - Lab 5
OPEN IN EDITOR:
191
~/chef-repo/cookbooks/webserver/recipes/default.rb
$ cd ~/chef-repo!
$ chef generate template cookbooks/webserver index.html
Create a template for index.html
Compiling Cookbooks...!
Recipe: code_generator::cookbook!
* directory[/root/chef-repo/webserver] action create!
- create new directory /root/chef-repo/webserver!
- restore selinux security context!
* template[/root/chef-repo/webserver/metadata.rb] action create_if_missing!
- create new file /root/chef-repo/webserver/metadata.rb!
- update content in file /root/chef-repo/webserver/metadata.rb from none to 4c0e2d!
(diff output suppressed by config)!
- restore selinux security context!
* template[/root/chef-repo/webserver/README.md] action create_if_missing!
<html>!
- create new file /root/chef-repo/webserver/README.md!
- update content in file /root/chef-repo/webserver/README.md from none to 5c3d3a!
(diff output suppressed by config)!
- restore selinux security context!
* cookbook_file[/root/chef-repo/webserver/chefignore] action create!
- create new file /root/chef-repo/webserver/chefignore!
- update content in file /root/chef-repo/webserver/chefignore from none to 9727b1!
(diff output suppressed by config)!
- restore selinux security context
192
OPEN IN EDITOR:
<html>!
<body>!
<h1>Hello, World!</h1>!
</body>!
</html>
193
Checkpoint - Lab 5
~/chef-repo/cookbooks/webserver/template/default/index.html.erb
Question: does it work???
• This is a great opportunity for test-driven
development
• TDD is a way to automatically verify that your
automation is producing expected results
• Test against cheap throwaway infrastructure
• e.g. inside containers!
194
$ cd ~/chef-repo!
$ sudo chef-client -z -r "recipe[webserver]"
Recipe: webserver::default!
* package[httpd] action install!
- install version 2.2.15-39.el6.centos of package httpd!
* service[httpd] action enable!
- enable service service[httpd]!
* service[httpd] action start!
- start service service[httpd]!
* template[/var/www/html/index.html] action create!
- create new file /var/www/html/index.html!
- update content in file /var/www/html/index.html from none to e043d5!
--- /var/www/html/index.html! 2015-01-11 12:05:11.281712169 +0000!
+++ /tmp/chef-rendered-template20150111-7749-3tgp7p! 2015-01-11 12:05:11.283712169 +0000!
@@ -1 +1,6 @@!
+ <h1>Hello, World!</h1>!
- restore selinux security context!
* service[iptables] action disable!
- disable service service[iptables]!
* service[iptables] action stop!
- stop service service[iptables]!
Running handlers:!
Running handlers complete!
Chef Client finished, 6/6 resources updated in 13.854983543 seconds
195
Apply our recipe using chef-client
$ curl http://localhost
<html>!
<body>!
<h1>Hello, World!</h1>!
</body>!
</html>
196
Display your custom homepage
Try it in a web browser
197
$ chef-client --local-mode -r "recipe[webserver]"
Starting Chef Client, version 11.18.0.rc.1!
resolving cookbooks for run list: ["webserver"]!
Synchronizing Cookbooks:!
- webserver!
Compiling Cookbooks...!
Converging 4 resources!
Recipe: webserver::default!
* package[httpd] action install (up to date)!
* service[httpd] action enable (up to date)!
* service[httpd] action start (up to date)!
* template[/var/www/html/index.html] action create (up to date)!
* service[iptables] action disable (up to date)!
* service[iptables] action stop (up to date)!
!
Running handlers:!
Running handlers complete!
Chef Client finished, 0/6 resources updated in 7.046113816 seconds
198
Run chef-client again
chef-client applying policies
199
chef-client
What policy should I follow?
Test & Repair
Apply the policy
recipe[webserver]
recipe[webserver]
Everything is up to date!
Test & Repair
• Gives you the ability to roll out new policies
• Helps avoid unintended changes being made to the
system
• Prevent manual change
• Prevent natural process of configuration drift
• Encourage a culture of capturing all configuration
200
Lab 6 - Display custom node data
• The Problem: We want our home page to display
the hostname of our node
!
• Success Criteria: We can see the hostname of our
node in a web browser
201
How do we get our node name?
• We could hard code the hostname of our node
• That’s a bummer because it doesn’t scale
• chef-client keeps a record of every node it manages
• We should be able to get the name of any node
managed by chef-client dynamically
• We can use the knife tool to view this chef-client
data
202
knife
• is an executable program used from the command
line to communicate with a Chef server
• can be used in local mode to mock Chef server
functionality
• in local-mode is a great way to explore some Chef
server functionality without committing to running a
Chef server just yet
• is included as a part of the ChefDK
203
$ knife node list --local-mode
List nodes we know about
WARNING: No knife configuration file found!
ip-172-31-25-147.us-west-2.compute.internal!
204
Node data from chef-client
• chef-client saves a node object at the end of a run
• In server mode, the Chef Server can be queried for
information about the node
• In local mode, the node object is saved to the local
filesystem
• A lot of this information comes from Ohai - we'll see
Ohai later.....
205
chef-client on our local vm
• We have a node record for our workstation because
we ran chef-client locally
!
• Again, this sort of recursive management is not the
way you’d do it in Production
206
Each node must have a unique name
• Every node Chef knows about must have a unique
name within an organization
• Chef defaults to the Fully Qualified Domain Name of
the server, i.e. in the format server.domain.com
• In EC2, this typically defaults to something that looks
like ip-x-x-x-x.region.compute.internal
207
$ knife node show ip-172-31-25-147.us-west-2.compute.internal --local-mode
Show node details with knife
WARNING: No knife configuration file found!
Node Name: ip-172-31-25-147.us-west-2.compute.internal!
Environment: _default!
FQDN: ip-172-31-25-147.us-west-2.compute.internal!
IP: 172.31.25.147!
Run List: recipe[webserver]!
Roles:!
Recipes: webserver, webserver::default!
Platform: centos 6.5!
Tags:
208
Pro-Tip: use $(hostname -f)
• We can get our node’s Fully Qualified Domain Name
in the right format using the hostname command
• hostname -f returns the full FQDN
209
$ knife node show $(hostname -f) --local-mode
Show node details with knife
WARNING: No knife configuration file found!
Node Name: ip-172-31-25-147.us-west-2.compute.internal!
Environment: _default!
FQDN: ip-172-31-25-147.us-west-2.compute.internal!
IP: 172.31.25.147!
Run List: recipe[webserver]!
Roles:!
Recipes: webserver, webserver::default!
Platform: centos 6.5!
Tags:
210
What is the Node object
• Nodes are made up of Attributes
• Many are discovered automatically (platform, ip
address, number of CPUs)
• Many other objects in Chef can also add Node
attributes (Cookbooks, Roles and Environments,
Recipes, Attribute Files)
211
Where is the Node object
• In server mode, node objects are stored and indexed
on the Chef Server
• In local mode, node objects are stored on the local
filesystem
!
• Node objects are stored in JSON
212
$ ls ~/chef-repo/nodes
List existing node objects
ip-172-31-25-147.us-west-2.compute.internal.json
213
$ less ~/chef-repo/nodes/$(hostname -f).json
Peek inside the node object
{!
"name": "ip-172-31-7-47.us-west-2.compute.internal",!
"normal": {!
"tags": [!
!
]!
},!
"automatic": {!
"keys": {!
"ssh": {!
"host_dsa_public": "AAAAB3NzaC1kc3MAAACBAIKx4i9XbyCQVvt2vStlkgNwLhHm5+kRHN3z!
5s8q+zseajCk+OxVoMzWAY4fj/5UOXpmZ2IJuGMF21RouO7HcZorNxOK5Y/1ABOUHec3NdZKBuPJcR14774F!
r2UpMFu5ugPlA0w+jgsS4HygHAharE2o5EFFrH9v09Pc0OTYqhpxAAAAFQDHEr5ZDB1Jze5Vc5hokWNKxkrS!
XwAAAIAudW/pKR9Dh0G4GqfW5hXdav/4tPQswvWpWorlThvlHTGfGnd8/W09jKFfTT/YMwqtvBLBqXbQApH6!
kCMa8SfNXVJwpi6TTusRTV2MJrPSp/lnJ3Ya/Qan/QFvI+axgTmhh9qZNEp9LiUzyOHrjLsoP8K38JX89A1j!
5gIFjw4gZgAAAIAWRjt7EuD3S+rdkzqzWiXXy8t8taLMednUqV1cpweWg6nKzcIkoEG5r4Anp7VYatTaG9Ur!
cR1XzCFsVgFULKA42r1skz1u8XLwZVhFR57j4A+NqyEiN17LHzPeQ/sfEVrZ67zWqkaxF3EdsqFMH1zhoE0q!
IZYGjOwTg6jbgIEiDw==",
214
Where does this data come from?
• Ohai is a discovery agent included with Chef
• It is executed every single time chef-client is run
• Extensible plugin model allows custom data
• Chef uses some information (e.g. platform ) to
make decisions about how to implement resources
215
Package Resource
package "git"
{
yum install git
!
apt-get install git
!
pacman sync git
!
pkg_add -r git
Providers aredetermined!
by node's platform
216
Ohai
"languages": {!
"ruby": {!
!
},!
"perl": {!
"version": "5.14.2",!
"archname": "x86_64-
linux-gnu-thread-multi"!
},!
"python": {!
"version": "2.6.6",!
"builddate": "Jul 10
2013, 22:48:45"!
},!
"perl": {!
"version": "version",!
"archname": "x86_64-
linux-thread-multi"!
},!
"lua": {!
"version": "5.1.4"!
},
"network": {!
"interfaces": {!
"lo": {!
"mtu": "16436",!
"flags": [!
"LOOPBACK", "UP","LOWER_UP"!
],!
"encapsulation": "Loopback",!
"addresses": {!
"127.0.0.1": {!
"family": "inet",!
"netmask": "255.0.0.0",!
"scope": "Node"!
},!
"::1": {!
"family": "inet6",!
"scope": "Node"!
}!
},!
},!
"eth0": {!
"type": "eth",!
"number": "0",
"kernel": {!
"name": "Linux", !
"release": "3.2.0-32-virtual",!
"version": "#1 SMP Wed Oct 16
18:37:12 UTC 2013",!
"machine": "x86_64",!
"modules": {!
"isofs": {!
"size": "70066",!
"refcount": "2"!
},!
"des_generic": {!
"size": "16604",!
"refcount": "0"!
}!
},!
"os": "GNU/Linux"!
},!
"os": "linux",!
"os_version":
"2.6.32-358.23.2.el6.x86_64",!
"ohai_time": 1389105685.7735305,
217
$ ohai | more
Run Ohai on node
{!
"languages": {!
"ruby": {!
"platform": "x86_64-linux",!
"version": "2.1.4",!
"release_date": "2014-10-27",!
"target": "x86_64-unknown-linux-gnu",!
"target_cpu": "x86_64",!
"target_vendor": "unknown",!
"target_os": "linux",!
"host": "x86_64-unknown-linux-gnu",!
"host_cpu": "x86_64",!
"host_os": "linux-gnu",!
"host_vendor": "unknown",!
"bin_dir": "/opt/chefdk/embedded/bin",!
"ruby_bin": "/opt/chefdk/embedded/bin/ruby",!
218
Node data
• To Chef, your infrastructure is just large hashes of data
stored as JSON
• Much of that data comes from Ohai
• e.g. The “languages” hash is detected via Ohai
• Some of that data is generated during a chef-client run
• e.g. node name is generated by chef-client
• All of this data is indexed and available for search
• When using a Chef Server, all of your infrastructure
configuration data is aggregated in one central location
219
$ knife node show $(hostname -f) --local-mode -a ipaddress
Show specific attributes with knife
WARNING: No knife configuration file found!
ip-172-31-7-47.us-west-2.compute.internal:!
ipaddress: 172.31.7.47
220
$ knife node show $(hostname -f) --local-mode -a cpu.0.model_name
Show specific attributes with knife
WARNING: No knife configuration file found!
ip-172-31-7-47.us-west-2.compute.internal:!
cpu.0.model_name: Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
221
$ knife node show $(hostname -f) --local-mode -a name
Show specific attributes with knife
WARNING: No knife configuration file found!
ip-172-31-25-147.us-west-2.compute.internal:!
name: ip-172-31-25-147.us-west-2.compute.internal
222
OPEN IN EDITOR:
<html>!
<body>!
<h1>Hello from <%= node.name %></h1> !
</body>!
</html>
223
Include node name in the index.html template
~/chef-repo/cookbooks/webserver/templates/default/index.html.erb
$ chef-client --local-mode -r "recipe[webserver]"
Compiling Cookbooks...!
Converging 4 resources!
Recipe: webserver::default!
* package[httpd] action install (up to date)!
* service[httpd] action enable (up to date)!
* service[httpd] action start (up to date)!
* template[/var/www/html/index.html] action create!
- update content in file /var/www/html/index.html from e043d5 to c1d241!
--- /var/www/html/index.html! 2015-01-11 12:05:11.283712169 +0000!
+++ /tmp/chef-rendered-template20150111-8914-mzgycj! 2015-01-11 13:05:09.112712168 +0000!
@@ -1,6 +1,6 @@!
<html>!
<html>!
<body>!
- <h1>Hello, World!</h1>!
+ <h1>Hello from ip-172-31-25-147.us-west-2.compute.internal!
</body>!
</html>!
- restore selinux security context
224
Apply our recipe using chef-client
Congratulations!
225
• You have just deployed a dynamic website!
Summary
• How is infrastructure referenced by Chef?
• Where do we get most data in those JSON hashes?
• Which three resources are the most commonly
found resources in configuration management?
226
Summary
• What questions can I answer for you?
227
AWS PopUp Loft - A Taste of Chef v2.0.0
Wrap Up
228
Recap & Next Steps
Tool Survey
• chef-apply
• chef
• chef-client in local mode
• knife in local mode
229
Vocabulary
• Resources
• Recipes
• Cookbooks
• Nodes
230
Resources
• Package
• File
• Template
• Service
231
Continued Learning
• The LearnChef Site
• Guided Tutorials
• Chef Fundamentals intro
http://learnchef.com
• How-To’s, Conference Talks, Webinars, more
http://youtube.com/user/getchef
• Attend a Chef Fundamentals Class
232
Further Resources
• http://chef.io
• http://docs.chef.io
• http://supermarket.chef.io
• http://lists.opscode.com
• irc.freenode.net #chef
• Twitter @chef #getchef, @learnchef #learnchef
233
Chef Fundamentals (Local)
• 2 Day Chef Fundamentals (San Francisco)
• February 3-4, 2015, 9am-5pm
• 2 Day Chef Fundamentals (San Francisco)
• March 5-6, 2015, 9am-5pm
!
• 25% OFF, use discount code: TSW25
234
Food Fight Show
• http://foodfightshow.org
• The Podcast Where
DevOps Chef Do Battle
• Regular updates about
new Cookbooks, Knife-
plugins, and more
• Best Practices for working
with Chef
235
@sigje sigje@chef.io

Weitere ähnliche Inhalte

Was ist angesagt?

Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Software, Inc.
 
Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5
Chef
 

Was ist angesagt? (20)

Chef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation Setup
 
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
 
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
 
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
 
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
 
Server Installation and Configuration with Chef
Server Installation and Configuration with ChefServer Installation and Configuration with Chef
Server Installation and Configuration with Chef
 
Chef ignited a DevOps revolution – BK Box
Chef ignited a DevOps revolution – BK BoxChef ignited a DevOps revolution – BK Box
Chef ignited a DevOps revolution – BK Box
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with Chef
 
Chef introduction
Chef introductionChef introduction
Chef introduction
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Understand Chef
Understand ChefUnderstand Chef
Understand Chef
 
Azure handsonlab
Azure handsonlabAzure handsonlab
Azure handsonlab
 
Chef fundamentals
Chef fundamentalsChef fundamentals
Chef fundamentals
 
Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5
 
Chef Tutorial for DEVOPS Newbies
Chef Tutorial for DEVOPS NewbiesChef Tutorial for DEVOPS Newbies
Chef Tutorial for DEVOPS Newbies
 
Common configuration with Data Bags - Fundamentals Webinar Series Part 4
Common configuration with Data Bags - Fundamentals Webinar Series Part 4Common configuration with Data Bags - Fundamentals Webinar Series Part 4
Common configuration with Data Bags - Fundamentals Webinar Series Part 4
 
Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1
 
Chef Cookbook Workflow
Chef Cookbook WorkflowChef Cookbook Workflow
Chef Cookbook Workflow
 
Chef, Devops, and You
Chef, Devops, and YouChef, Devops, and You
Chef, Devops, and You
 
Opscode tech festa july 2013
Opscode tech festa   july 2013Opscode tech festa   july 2013
Opscode tech festa july 2013
 

Andere mochten auch

The Effects of Vehicle Speeds on Accident Frequency within Settlements along ...
The Effects of Vehicle Speeds on Accident Frequency within Settlements along ...The Effects of Vehicle Speeds on Accident Frequency within Settlements along ...
The Effects of Vehicle Speeds on Accident Frequency within Settlements along ...
IJMER
 
How To Talk To Anyone - Book Review
How To Talk To Anyone - Book ReviewHow To Talk To Anyone - Book Review
How To Talk To Anyone - Book Review
IES MCRC
 
Inmotionhosting metroblog com_bluehost_reviews_is_their_host
Inmotionhosting metroblog com_bluehost_reviews_is_their_hostInmotionhosting metroblog com_bluehost_reviews_is_their_host
Inmotionhosting metroblog com_bluehost_reviews_is_their_host
Rancyna James
 
Проект Киноклуб(1)
Проект Киноклуб(1)Проект Киноклуб(1)
Проект Киноклуб(1)
Anna Mazina
 
Dx2645324539
Dx2645324539Dx2645324539
Dx2645324539
IJMER
 
Cy3210661070
Cy3210661070Cy3210661070
Cy3210661070
IJMER
 
დეპრესია
დეპრესიადეპრესია
დეპრესია
Nini Talabadze
 

Andere mochten auch (20)

What Makes a Good Chef Cookbook? (May 2014 Edition)
What Makes a Good Chef Cookbook? (May 2014 Edition)What Makes a Good Chef Cookbook? (May 2014 Edition)
What Makes a Good Chef Cookbook? (May 2014 Edition)
 
Introduction to Docker & CoreOS - Symfony User Group Cologne
Introduction to Docker & CoreOS - Symfony User Group CologneIntroduction to Docker & CoreOS - Symfony User Group Cologne
Introduction to Docker & CoreOS - Symfony User Group Cologne
 
Introduction to chef
Introduction to chefIntroduction to chef
Introduction to chef
 
Chef Cookbook Testing and Continuous Integration
Chef Cookbook Testing and Continuous IntegrationChef Cookbook Testing and Continuous Integration
Chef Cookbook Testing and Continuous Integration
 
Jenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentJenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated Deployment
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with Chef
 
Prospect of bioenergy substitution in tea industries of North East India
Prospect of bioenergy substitution in tea industries of North East IndiaProspect of bioenergy substitution in tea industries of North East India
Prospect of bioenergy substitution in tea industries of North East India
 
The Effects of Vehicle Speeds on Accident Frequency within Settlements along ...
The Effects of Vehicle Speeds on Accident Frequency within Settlements along ...The Effects of Vehicle Speeds on Accident Frequency within Settlements along ...
The Effects of Vehicle Speeds on Accident Frequency within Settlements along ...
 
Optimization of Turning Parameters Using Taguchi Method
Optimization of Turning Parameters Using Taguchi MethodOptimization of Turning Parameters Using Taguchi Method
Optimization of Turning Parameters Using Taguchi Method
 
Measurement Of Rn222 Concentrations In The Air Of Peshraw & Darbandikhan Tu...
Measurement Of Rn222  Concentrations In The Air Of Peshraw &  Darbandikhan Tu...Measurement Of Rn222  Concentrations In The Air Of Peshraw &  Darbandikhan Tu...
Measurement Of Rn222 Concentrations In The Air Of Peshraw & Darbandikhan Tu...
 
How To Talk To Anyone - Book Review
How To Talk To Anyone - Book ReviewHow To Talk To Anyone - Book Review
How To Talk To Anyone - Book Review
 
Hip hop
Hip hopHip hop
Hip hop
 
Inmotionhosting metroblog com_bluehost_reviews_is_their_host
Inmotionhosting metroblog com_bluehost_reviews_is_their_hostInmotionhosting metroblog com_bluehost_reviews_is_their_host
Inmotionhosting metroblog com_bluehost_reviews_is_their_host
 
Проект Киноклуб(1)
Проект Киноклуб(1)Проект Киноклуб(1)
Проект Киноклуб(1)
 
Eleni
EleniEleni
Eleni
 
The Bloch Space of Analytic functions
The Bloch Space of Analytic functionsThe Bloch Space of Analytic functions
The Bloch Space of Analytic functions
 
Dx2645324539
Dx2645324539Dx2645324539
Dx2645324539
 
Cy3210661070
Cy3210661070Cy3210661070
Cy3210661070
 
დეპრესია
დეპრესიადეპრესია
დეპრესია
 
Monitor the Unmeasurable
Monitor the UnmeasurableMonitor the Unmeasurable
Monitor the Unmeasurable
 

Ähnlich wie Introduction to Chef - Techsuperwomen Summit

Chef for Openstack
Chef for OpenstackChef for Openstack
Chef for Openstack
Mohit Sethi
 
Chef + AWS + CodeIgniter
Chef + AWS + CodeIgniterChef + AWS + CodeIgniter
Chef + AWS + CodeIgniter
ciconf
 

Ähnlich wie Introduction to Chef - Techsuperwomen Summit (20)

Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015
 
Testable Infrastructure with Chef, Test Kitchen, and Docker
Testable Infrastructure with Chef, Test Kitchen, and DockerTestable Infrastructure with Chef, Test Kitchen, and Docker
Testable Infrastructure with Chef, Test Kitchen, and Docker
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
 
OSDC 2013 | Introduction into Chef by Andy Hawkins
OSDC 2013 | Introduction into Chef by Andy HawkinsOSDC 2013 | Introduction into Chef by Andy Hawkins
OSDC 2013 | Introduction into Chef by Andy Hawkins
 
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowTXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
 
Chef for openstack
Chef for openstackChef for openstack
Chef for openstack
 
SCALE12X: Chef for OpenStack
SCALE12X: Chef for OpenStackSCALE12X: Chef for OpenStack
SCALE12X: Chef for OpenStack
 
Compliance Automation with InSpec - Chef NYC Meetup - April 2017
Compliance Automation with InSpec - Chef NYC Meetup - April 2017Compliance Automation with InSpec - Chef NYC Meetup - April 2017
Compliance Automation with InSpec - Chef NYC Meetup - April 2017
 
Chef for Openstack
Chef for OpenstackChef for Openstack
Chef for Openstack
 
AWS re:Invent 2016: Configuration Management in the Cloud (DEV305)
AWS re:Invent 2016: Configuration Management in the Cloud (DEV305)AWS re:Invent 2016: Configuration Management in the Cloud (DEV305)
AWS re:Invent 2016: Configuration Management in the Cloud (DEV305)
 
Chef + AWS + CodeIgniter
Chef + AWS + CodeIgniterChef + AWS + CodeIgniter
Chef + AWS + CodeIgniter
 
Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011Standardizing and Managing Your Infrastructure - MOSC 2011
Standardizing and Managing Your Infrastructure - MOSC 2011
 
Using Nagios with Chef
Using Nagios with ChefUsing Nagios with Chef
Using Nagios with Chef
 
Automated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. AnsibleAutomated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. Ansible
 
Chef: Smart infrastructure automation
Chef: Smart infrastructure automationChef: Smart infrastructure automation
Chef: Smart infrastructure automation
 
Network Infrastructure as Code with Chef and Cisco
Network Infrastructure as Code with Chef and CiscoNetwork Infrastructure as Code with Chef and Cisco
Network Infrastructure as Code with Chef and Cisco
 
DEVNET-1007 Network Infrastructure as Code with Chef and Cisco
DEVNET-1007	Network Infrastructure as Code with Chef and CiscoDEVNET-1007	Network Infrastructure as Code with Chef and Cisco
DEVNET-1007 Network Infrastructure as Code with Chef and Cisco
 
AWS OpsWorks for Chef Automate
AWS OpsWorks for Chef AutomateAWS OpsWorks for Chef Automate
AWS OpsWorks for Chef Automate
 
Tool up your lamp stack
Tool up your lamp stackTool up your lamp stack
Tool up your lamp stack
 
Tool Up Your LAMP Stack
Tool Up Your LAMP StackTool Up Your LAMP Stack
Tool Up Your LAMP Stack
 

Mehr von Jennifer Davis

Dungeons and Data - Yahoo Hack Day 2013
Dungeons and Data - Yahoo Hack Day 2013Dungeons and Data - Yahoo Hack Day 2013
Dungeons and Data - Yahoo Hack Day 2013
Jennifer Davis
 

Mehr von Jennifer Davis (19)

Crafting Reusable Resources
Crafting Reusable ResourcesCrafting Reusable Resources
Crafting Reusable Resources
 
Effective DevOps - Pittsburgh Techfest 2016
Effective DevOps - Pittsburgh Techfest 2016Effective DevOps - Pittsburgh Techfest 2016
Effective DevOps - Pittsburgh Techfest 2016
 
Magic Myth and the DevOps, ANTIDOTES TO LEARNED HELPLESSNESS AND FEAR CULTURE...
Magic Myth and the DevOps, ANTIDOTES TO LEARNED HELPLESSNESS AND FEAR CULTURE...Magic Myth and the DevOps, ANTIDOTES TO LEARNED HELPLESSNESS AND FEAR CULTURE...
Magic Myth and the DevOps, ANTIDOTES TO LEARNED HELPLESSNESS AND FEAR CULTURE...
 
Effective Tools for Effective Change
Effective Tools for Effective ChangeEffective Tools for Effective Change
Effective Tools for Effective Change
 
Effective Devops - Velocity New York 2015
Effective Devops - Velocity New York 2015 Effective Devops - Velocity New York 2015
Effective Devops - Velocity New York 2015
 
Tools Effecting Change - DevOpsDays Boston 2015
Tools Effecting Change - DevOpsDays Boston 2015Tools Effecting Change - DevOpsDays Boston 2015
Tools Effecting Change - DevOpsDays Boston 2015
 
DevOps DC - Magic Myth and the DevOps
DevOps DC - Magic Myth and the DevOpsDevOps DC - Magic Myth and the DevOps
DevOps DC - Magic Myth and the DevOps
 
Effective Devops - AWS Loft Event June 2015
Effective Devops - AWS Loft Event June 2015Effective Devops - AWS Loft Event June 2015
Effective Devops - AWS Loft Event June 2015
 
Effective Devops - Collaboration and Tools - Velocity Santa Clara 2015
Effective Devops - Collaboration and Tools - Velocity Santa Clara 2015Effective Devops - Collaboration and Tools - Velocity Santa Clara 2015
Effective Devops - Collaboration and Tools - Velocity Santa Clara 2015
 
Magic Myth and the Devops - Cascadia IT 2015
Magic Myth and the Devops - Cascadia IT 2015Magic Myth and the Devops - Cascadia IT 2015
Magic Myth and the Devops - Cascadia IT 2015
 
Planning Application Resilience
Planning Application ResiliencePlanning Application Resilience
Planning Application Resilience
 
Planning Application Resilience - Developer Week 2015
Planning Application Resilience - Developer Week 2015Planning Application Resilience - Developer Week 2015
Planning Application Resilience - Developer Week 2015
 
Magic, Myth and the DevOps
Magic, Myth and the DevOpsMagic, Myth and the DevOps
Magic, Myth and the DevOps
 
From Hero to Zero - DevOpsDays Boston
From Hero to Zero - DevOpsDays BostonFrom Hero to Zero - DevOpsDays Boston
From Hero to Zero - DevOpsDays Boston
 
Velocity 2014 - From Hero to Zero
Velocity 2014 - From Hero to ZeroVelocity 2014 - From Hero to Zero
Velocity 2014 - From Hero to Zero
 
Implementing Kanban to Improve your Workflow
Implementing Kanban to Improve your WorkflowImplementing Kanban to Improve your Workflow
Implementing Kanban to Improve your Workflow
 
Dungeons and Data - Yahoo Hack Day 2013
Dungeons and Data - Yahoo Hack Day 2013Dungeons and Data - Yahoo Hack Day 2013
Dungeons and Data - Yahoo Hack Day 2013
 
Building Large Scale Services - LISA 2013
Building Large Scale Services - LISA 2013 Building Large Scale Services - LISA 2013
Building Large Scale Services - LISA 2013
 
Visualizing Self - Exploring Your Personal Metrics
Visualizing Self - Exploring Your Personal MetricsVisualizing Self - Exploring Your Personal Metrics
Visualizing Self - Exploring Your Personal Metrics
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Introduction to Chef - Techsuperwomen Summit

  • 1. Tech Superwomen Summit - v 1.0.0 Introduction to Chef training@getchef.com Copyright (C) 2015 Chef Software, Inc. 1
  • 2. Pre-Requisites • Laptop with an SSH client • Basic Unix command line knowledge • Wireless: UCSFguest 2
  • 3. AWS PopUp Loft - A Taste of Chef v2.0.0 Introductions 3
  • 4. Course Instructor 4 Jennifer Davis Solutions Engineer Email:sigje@chef.io Twitter: @sigje
  • 5. Communicate and Collaborate • Hashtags: #TSWS15 #getchef 5
  • 6. Instructor Introduction • Name: Franklin Webber • Current job role: Developer / Instructor • Previous job roles/background: ARMY SGT, QA, SDET • Experience with Chef/Config Management: Deployments with Ruby on Rails Applications • Favorite Text Editor: Sublime Text 6
  • 7. Introduce Yourselves • Name • Current job role • Previous job roles/background • Experience with infrastructure/automation • Experience with Chef and/or config management 7
  • 8. AWS PopUp Loft - A Taste of Chef v2.0.0 Course Objectives and Style 8
  • 9. Course Objectives • Upon completion of this course you will be able to • Automate common infrastructure tasks with Chef • Describe some of Chef’s tools • Apply Chef’s primitives to solve your problems • Know where to go for more info 9
  • 10. Learning Chef • You bring domain expertise about your business and problems to solve. • Chef provides a framework to solve problems. • Together, we work together to help you express solutions to your problems with Chef. 10
  • 11. Chef is a Language • Learning Chef is like learning the basics of a language • 80% fluency reached quickly • The remaining 20% just takes practice • The best way to learn Chef is to use Chef 11
  • 12. Training is a discussion • Lots of hands on labs • Lots of typing • Ask questions when they come to you • Ask for help when you need it • Help each other • We will troubleshoot issues on the spot 12
  • 13. Just an Introduction • This course is an introduction to using Chef to manage your infrastructure. • We cover a lot of material! • Any discussion items that are too far off topic will be captured • We'll return to these items as time permits 13
  • 14. Setting Expectations • Experience Level: Beginner • Flexible content based on class • It’s ok to leave (and come back). 14
  • 15. AWS PopUp Loft - A Taste of Chef v2.0.0 Agenda 15
  • 16. Topics • Introduction to Infrastructure Automation • Overview of Chef • Workstation Setup • Resources • Describing Policies • Wrap Up 16
  • 17. Breaks! • We’ll take a break as often as we need them. • We’ll take a break for lunch. 17
  • 18. AWS PopUp Loft - A Taste of Chef v2.0.0 Legend 18
  • 19. $ ifconfig Legend: Example Terminal Command and Output lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICA ST> mtu 16384! !options=3<RXCSUM,TXCSUM>! !inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1! !inet 127.0.0.1 netmask 0xff000000! 19
  • 20. OPEN IN EDITOR: SAVE FILE! ~/hello_world Hi!! ! I am a friendly file. Legend: Example of editing a file on your workstation 20
  • 21. AWS PopUp Loft - A Taste of Chef v2.0.0 Infrastructure Automation 21
  • 22. What is Infrastructure Automation? 22
  • 24. Applications • MongoDB • Apache • Java • Drupal • WordPress • cakephp 24
  • 25. Applications - Complexity •Single service == multiple applications. •Single application == a component of service. 25
  • 26. Configurations • Operating Systems • Software • Network • Storage 26
  • 27. Configurations - Complexity •Multiple services using same software with different configurations. •Different Operating Systems requiring same software (and user experience). 27
  • 28. Access Control • Users • Groups • Organizations 28
  • 29. Access Control - Complexity •Different users access to different systems. •External versus internal. •Compliance. 29
  • 30. Data • Tweets • Profiles • Emails 
 Specific to your organization. 30
  • 31. Servers • physical hardware • cloud services • virtual 31
  • 32. Servers - Complexity •Specialization in hardware. •Lack of standardization. 32
  • 33. Network & Storage • routers • switches • firewalls • tape libraries • NAS/SAN attached storage 33
  • 36. Automaton • acting of one’s own will. 36
  • 37. Automation • reducing labor, energy, and materials • improve quality, precision, accuracy 37
  • 38. What is infrastructure automation? 38
  • 39. Infrastructure Automation is creating control systems that reduce the burden on people to manage services and increase the quality, accuracy and precision of a service to the consumers of the service. 39
  • 40. AWS PopUp Loft - A Taste of Chef v2.0.0 Overview of Chef 40
  • 43. Automation Platform • Dependable view of your network’s state. • Handles complex dependencies among nodes. • Fault tolerant. • Secure. • Multi-platform. • Supports multiple compute platforms. • Foundation for innovation. 43
  • 44. Infrastructure as Code • Programmatically provision and configure components. 44
  • 45. Infrastructure as Code • Treat like any code base. 45
  • 46. Infrastructure as Code • Reconstruct business from code repository, data backup, and compute resources. 46
  • 47. Infrastructure as Code • Programmatically provision and configure components. • Treat like any other code base. • Reconstruct business from code repository, data backup, and compute resources. 47
  • 48. Policy-based Management • You capture the policy for your infrastructure in code. • Chef ensures each node in your infrastructure complies with the policy. 48
  • 49. Policy-based Management • Chef provides a domain-specific language (DSL) that allows you to specify policy for your infrastructure • Policy describes the desired state • Policies can be statically or dynamically defined. 49
  • 52. AWS PopUp Loft - A Taste of Chef v2.0.0 Workstation Setup Getting Started 52
  • 53. Pre-Configured Workstation • http://bit.ly/15NJUR0 • chef-dk installed via: • curl -L https://www.getchef.com/chef/install.sh | sudo bash -s -- -P chefdk 53
  • 54. Chef Development Kit • Contains everything you need to start using Chef • The new “chef” tool • Chef-client distribution • Testing frameworks • Linting tools • https://downloads.chef.io/chef-dk/ 54
  • 55. SSH to your instance • Login: chef • Password: chef ! • ssh root@IPADDRESS 55
  • 56. $ touch NAME_INTRO; ls | grep INTRO Verify your node jenniferdavis_INTRO 56
  • 57. $ chef verify Verify your chef installation Running verification for component 'berkshelf'! Running verification for component 'test-kitchen'! Running verification for component 'chef-client'! Running verification for component 'chef-dk'! Running verification for component 'chefspec'! Running verification for component 'rubocop'! Running verification for component 'fauxhai'! Running verification for component 'knife-spork'! Running verification for component 'kitchen-vagrant'! Running verification for component 'package installation' 57
  • 58. AWS PopUp Loft - A Taste of Chef v2.0.0 Resources 58 Fundamental Building Blocks
  • 60. Infrastructure Elements • the individual components or building blocks we have access to automate. 60
  • 62. Resources • A resource represents an element or component of the system and the desired state of that element. 62
  • 63. package "haproxy" do! action :install! end Resources - Package • Package that should be installed 63
  • 64. service "iptables" do! action [ :start, :enable ]! end Resources - Service • Service that should be running and enabled to start on reboot 64
  • 65. cron "restart webserver" do! hour "2"! minute "0"! command "service httpd restart"! end Resources - Cron • Cron job that should be configured 65
  • 66. user "nginx" do! comment "nginx user" ! uid "500" ! gid "500"! supports :manage_home => true ! end Resources - User • User that should be managed 66
  • 67. dsc_script "emacs" do! code <<-EOH! Environment 'texteditor'! {! Name = 'EDITOR'! Value = 'c:emacsbinemacs.exe'! }! EOH! end Resources - DSC • A Desired State Configuration setting that should be applied 67
  • 68. registry_key “HKEY_LOCAL_MACHINE SOFTWAREMicrosoftWindows CurrentVersionPolicies System” do! values [{! :name => "Enable LUA”,! :type => :dword,! :data => 0! }]! end! Resources - Registry Key • Registry Key that should be created 68
  • 69. package "haproxy" do! action :install! end Resources - Package • Package that should be installed 69
  • 70. Resources • A resource represents an element or component of the system and the desired state of that element. • https://docs.chef.io/chef/resources.html 70
  • 71. Lab 1 - Install a text editor • Problem: Our workstation does not have $EDITOR installed ! • Success Criteria: You can edit files with $EDITOR ! • $EDITOR is your favorite command line text editor: vim, emacs, or nano 71
  • 72. $ ssh chef@IPADDRESS SSH to your workstation chef@54.88.161.76's password: Last login: Fri Jan 30 06:18:29 2015 from 12.232.194.107 72
  • 73. $ which vim Is $EDITOR installed? [chef@ip-172-31-35-99 ~]$ which vim /usr/bin/vim 73
  • 74. $ which nano Is $EDITOR installed? [chef@ip-172-31-35-99 ~]$ which nano /usr/bin/which: no nano in (/usr/local/bin:/ bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/ home/chef/bin) 74
  • 75. chef-apply • chef-apply is an executable program that allows you to work with resources • Is included as a part of the ChefDK • A great way to explore resources • NOT how you will eventually use Chef in production 75
  • 76. $ chef-apply --help What does chef-apply do? Usage: chef-apply [RECIPE_FILE] [-e RECIPE_TEXT] [-s] --[no-]color Use colored output, defaults to enabled -e, --execute RECIPE_TEXT Execute resources supplied in a string -l, --log_level LEVEL Set the log level (debug, info, warn, error, fatal) -s, --stdin Execute resources read from STDIN -v, --version Show chef version -W, --why-run Enable whyrun mode -h, --help Show this message 76
  • 77. $ chef-apply -e "package 'vim'" Install vim [chef@ip-172-31-35-99 ~]$ chef-apply -e "package 'vim'" Recipe: (chef-apply cookbook)::(chef-apply recipe) * package[vim] action install (up to date) 77
  • 78. $ chef-apply -e "package 'emacs'" Install emacs Recipe: (chef-apply cookbook)::(chef-apply recipe) * package[emacs] action install - install version 23.1-25.el6 of package emacs 78
  • 79. $ sudo chef-apply -e "package 'nano'" Install nano Recipe: (chef-apply cookbook)::(chef-apply recipe) * package[nano] action install - install version 2.0.9-7.el6 of package nano 79
  • 80. Resources • Describe the desired state • Do not need to tell Chef how to get there ! • What happens if you re-run the chef-apply command? 80
  • 81. $ chef-apply -e "package 'vim'" Install vim Recipe: (chef-apply cookbook)::(chef-apply recipe) * package[vim] action install (up to date) 81
  • 82. package "vim" Test and Repair • Resources follow a test and repair model 82
  • 83. package "vim" Test and Repair • Resources follow a test and repair model 83 Is vim installed?Test
  • 84. package "vim" Test and Repair • Resources follow a test and repair model 84 Is vim installed? Yes Test
  • 85. package "vim" Test and Repair • Resources follow a test and repair model 85 Is vim installed? Yes Done Test
  • 86. package "vim" Test and Repair • Resources follow a test and repair model 86 Is vim installed? Yes No Done Test
  • 87. package "vim" Test and Repair • Resources follow a test and repair model 87 Is vim installed? Yes No Install itDone Test
  • 88. package "vim" Test and Repair • Resources follow a test and repair model 88 Is vim installed? Yes No Install itDone Test Repair
  • 89. Resources: Test and Repair • Resources follow a test & repair model ! • Resource currently in the desired state? (test) • Yes - Do nothing • No - Bring the resource into the desired state (repair) 89
  • 90. • dsc_script • registry_key • powershell_script • cron • mount • route • … and more! Resources • package • template • service • directory • user • group 90
  • 91. Lab 2 - Hello World! • Problem: Oops, we forgot to start with “hello world” ! • Success Criteria: A file with “Hello, World!” content is available in our home directory 91
  • 92. Recipe • A recipe is an ordered list of resources. • Chef DSL is ruby. • Recipe stored in file with .rb extension. 92
  • 93. SAVE FILE! file "hello.txt" do! action :create! content "Hello, World!"! mode "0644"! owner "root"! group "root"! end Hello, World! OPEN IN EDITOR: ~/hello.rb 93
  • 94. Review • hello.rb - recipe we created. • hello.txt - the file we want to manage through file resource. 94 hello.rb hello.txt Recipe File Hello, world!
  • 95. $ sudo chef-apply hello.rb Apply hello.rb Recipe: (chef-apply cookbook)::(chef-apply recipe)! * file[hello.txt] action create! - create new file hello.txt! - update content in file hello.txt from none to dffd60! --- hello.txt! 2015-01-11 08:36:50.195712169 +0000! +++ /tmp/.hello.txt20150111-5823-4tggr4!2015-01-11 08:36:50.196712169 +0000! @@ -1 +1,2 @@! +Hello, World!! - change mode from '' to '0644'! - change owner from '' to 'root'! - change group from '' to 'root'! - restore selinux security context 95
  • 96. $ cat hello.txt Read hello.txt Hello, World! 96
  • 98. file "hello.txt" Chef Resources • Have a type • Have a name 98
  • 99. file "hello.txt" do! ! ! end Chef Resources • Have a type • Have a name • Include details between keywords do and end 99
  • 100. file "hello.txt" do! action :create! end Chef Resources • Have a type • Have a name • Include details between keywords do and end • Describe the state using keyword action 100
  • 101. file "hello.txt" do! action :create! end Chef Resources — In Plain English • The TYPE named NAME should be ACTION’ed ! • The file named “hello.txt” should be created 101
  • 102. file "hello.txt" do! action :create! content "Hello, World!"! mode "0644"! owner "root"! group "root"! end Chef Resources • Have a type • Have a name • Include details between keywords do and end • Describe the state using keyword action • Include additional details about the state of the thing (attributes) 102
  • 103. file "hello.txt" do! action :create! content "Hello, World!"! mode "0644"! owner "root"! group "root"! end • The TYPE named NAME should be ACTION’ed with ATTRIBUTES 103 Chef Resources — In Plain English
  • 104. file "hello.txt" do! action :create! content "Hello, World!"! mode "0644"! owner "root"! group "root"! end • The file named “hello.txt” should be created with content of “Hello, World!”, permissions of 0644, owned by the be root user and root group 104 Chef Resources — In Plain English
  • 105. $ chef-apply hello.rb Re-apply hello.rb Recipe: (chef-apply cookbook)::(chef-apply recipe)! * file[hello.txt] action create (up to date) 105
  • 106. Resources: Test and Repair • Resources follow a test & repair model ! • Resource currently in the desired state? (test) • Yes - Do nothing • No - Bring the resource into the desired state (repair) 106
  • 107. What if…? • Change the content of the file using your favorite text editor? • Change the ownership of the file? • Delete the file? 107
  • 108. Let’s look at the File Resource • http://docs.chef.io/chef/resources.html#file 108
  • 109. Lab 2 - Hello World! • Problem: Clean up “Hello World” file. ! • Success Criteria: Deletion of hello.txt file. 109
  • 110. Lab 2 - Hello World! • We will create a new recipe called goodbye. • Where will this be saved? • What type of resource will we use? • What is the name of the resource? • What action? 110
  • 111. SAVE FILE! file "hello.txt" do! action :delete! end Goodbye Hello, World! OPEN IN EDITOR: ~/goodbye.rb 111
  • 112. $ chef-apply goodbye.rb Apply goodbye.rb 112
  • 113. • dsc_script • registry_key • powershell_script • cron • mount • route Resources • package • template • service • directory • user • group 113
  • 114. Resources • What states can a file be in? • What state will a file be in if you don’t declare an action? • What state will a package be in if you don’t declare an action? • Do you have to indent the attributes of a resource? • What Chef tool allows us to easily explore resources? 114
  • 115. Lab 3 - Manage a file • Problem: We want users logging into the system to see “Property of COMPANY NAME” upon login. • Success Criteria: An updated /etc/motd with “Property of COMPANY NAME” that is displayed on login. 115
  • 116. Lab 3 - Manage a file • The file named /etc/motd should have the contents “Property of COMPANY NAMEn”, permissions of “0644”, and owned by the group and user named “root” 116
  • 117. Summary • What questions can I answer for you? 117
  • 118. AWS PopUp Loft - A Taste of Chef v2.0.0 Describing Policies 118 Recipes & Cookbooks
  • 119. Resources > Recipes > Cookbooks • A resource is a piece of the system and its desired state • A recipe is a collection of resources • A cookbook is a collection of recipes • Cookbooks can also contain ingredients • A cookbook is a “package” of policy information 119
  • 120. Recipe - A collection of resources 120 package "haproxy" do! action :install! end! ! template "/etc/haproxy/haproxy.cfg" do! source "haproxy.cfg.erb"! owner "root"! group "root"! mode "0644"! notifies :restart, "service[haproxy]"! end! ! service "haproxy" do! supports :restart => :true! action [:enable, :start]! end
  • 121. • Body Level One • Body Level Two • Body Level Three • Body Level Four • Body Level Five Order Matters package "haproxy" do! action :install! end! ! template "/etc/haproxy/haproxy.cfg" do! source "haproxy.cfg.erb"! owner "root"! group "root"! mode "0644"! notifies :restart, "service[haproxy]"! end! ! service "haproxy" do! supports :restart => :true! action [:enable, :start]! end • Resources are executed in order 1st 121
  • 122. • Body Level One • Body Level Two • Body Level Three • Body Level Four • Body Level Five Order Matters package "haproxy" do! action :install! end! ! template "/etc/haproxy/haproxy.cfg" do! source "haproxy.cfg.erb"! owner "root"! group "root"! mode "0644"! notifies :restart, "service[haproxy]"! end! ! service "haproxy" do! supports :restart => :true! action [:enable, :start]! end • Resources are executed in order 1st 2nd 122
  • 123. • Body Level One • Body Level Two • Body Level Three • Body Level Four • Body Level Five Order Matters package "haproxy" do! action :install! end! ! template "/etc/haproxy/haproxy.cfg" do! source "haproxy.cfg.erb"! owner "root"! group "root"! mode "0644"! notifies :restart, "service[haproxy]"! end! ! service "haproxy" do! supports :restart => :true! action [:enable, :start]! end • Resources are executed in order 1st 2nd 3rd 123
  • 124. Cookbook • A “package” for Chef policies • Typically map 1:1 to a piece of software or functionality • Distribution unit • Versioned • Modular and re-usable 124
  • 125. Abstracting Data from Policy • Policy - The desired state of the system. • Data - The details that might change. 125
  • 126. Abstracting Data from Policy • Policy - Tomcat should be installed • Data - It should be version 6 and listening on 8080 126
  • 127. Abstracting Data from Policy • Policy - A file should exist • Data - The content of that file 127
  • 128. Lab 4 - Manage Data & Policy Separately • Problem: The policy for managing file/etc/motd currently has state intermingled with content ! • Success Criteria: We have a policy that manages the state and content of /etc/motd separately 128
  • 129. file "/etc/motd" do! content "Property of COMPANY NAME" ! action :create! mode "0644" ! owner "root" ! group "root"! end Message of the day • State — policy that describes the resource 129
  • 130. file "/etc/motd" do! content "Property of COMPANY NAME" ! action :create! mode "0644" ! owner "root" ! group "root"! end Message of the day • Content — data that may change independently of policy changes 130
  • 131. Cookbooks contain ingredients • Cookbooks allow you to package up separate components in one distributable unit • Cookbooks contain recipes (policy) • Cookbooks can also contain files to distribute (content) 131
  • 132. Lab 4 - Manage Data & Policy Separately • Required steps: • Create a repository to store our cookbooks • Create a cookbook • Separate policy from data 132
  • 133. The chef-repo • Chef cookbooks should be stored in a version control system • You have options for how best to manage your repository of chef code • We will create a single chef-repo for all of our cookbooks 133
  • 134. The “chef” command • chef is an executable command line tool for • generating cookbooks, recipes, and other things that make up your Chef code • ensuring RubyGems are downloaded properly for your development environment • verifying that all the Chef components are installed and configured correctly • Included with ChefDK 134
  • 135. $ chef generate --help Usage: chef generate GENERATOR [options]! ! Available generators:! app Generate an application repo! cookbook Generate a single cookbook! recipe Generate a new recipe! attribute Generate an attributes file! template Generate a file template! file Generate a cookbook file! lwrp Generate a lightweight resource/provider! repo Generate a Chef policy repository! policyfile Generate a Policyfile for use with the install/push commands (experimental) 135 What can “chef” generate?
  • 136. $ chef generate repo --help Usage: chef generate repo NAME [options]! -C, --copyright COPYRIGHT Name of the copyright holder - defaults to 'The Authors'! -m, --email EMAIL Email address of the author - defaults to 'you@example.com'! -a, --generator-arg KEY=VALUE Use to set arbitrary attribute KEY to VALUE in the code_generator cookbook! -I, --license LICENSE all_rights, apache2, mit, gplv2, gplv3 - defaults to all_rights! -p, --policy-only Create a repository for policy only, not cookbooks! -g GENERATOR_COOKBOOK_PATH, Use GENERATOR_COOKBOOK_PATH for the code_generator cookbook! --generator-cookbook 136 How do we generate a repo?
  • 137. $ cd ~ 137 Start from home directory
  • 138. $ chef generate repo chef-repo Compiling Cookbooks...! Recipe: code_generator::repo! * directory[/root/chef-repo] action create! - create new directory /root/chef-repo! - restore selinux security context! * template[/root/chef-repo/LICENSE] action create! - create new file /root/chef-repo/LICENSE! - update content in file /root/chef-repo/LICENSE from none to aed48c! (diff output suppressed by config)! - restore selinux security context! * cookbook_file[/root/chef-repo/README.md] action create! - create new file /root/chef-repo/README.md! - update content in file /root/chef-repo/README.md from none to 767ead! (diff output suppressed by config)! - restore selinux security context! * cookbook_file[/root/chef-repo/Rakefile] action create! - create new file /root/chef-repo/Rakefile! - update content in file /root/chef-repo/Rakefile from none to 108932! (diff output suppressed by config)! - restore selinux security context 138 Make a chef repo
  • 139. $ tree !"" chef-repo! #"" certificates! $   !"" README.md! #"" chefignore! #"" config! $   !"" rake.rb! #"" cookbooks! $   !"" README.md! #"" data_bags! $   !"" README.md! #"" environments! $   !"" README.md! #"" LICENSE! #"" Rakefile! #"" README.md! !"" roles! !"" README.md 139 Examine chef-repo
  • 140. Lab 4 - Manage Data & Policy Separately • Required steps: ✔️ Create a repository to store our cookbooks • Create a cookbook • Separate policy from data 140
  • 141. $ chef generate cookbook --help Usage: chef generate cookbook NAME [options]! -C, --copyright COPYRIGHT Name of the copyright holder - defaults to 'The Authors'! -m, --email EMAIL Email address of the author - defaults to 'you@example.com'! -a, --generator-arg KEY=VALUE Use to set arbitrary attribute KEY to VALUE in the code_generator cookbook! -I, --license LICENSE all_rights, apache2, mit, gplv2, gplv3 - defaults to all_rights! -g GENERATOR_COOKBOOK_PATH, Use GENERATOR_COOKBOOK_PATH for the code_generator cookbook! --generator-cookbook 141 How do we generate a cookbook?
  • 142. $ chef generate cookbook cookbooks/motd Compiling Cookbooks...! Recipe: code_generator::cookbook! * directory[/tmp/chef-repo/cookbooks/motd] action create! - create new directory /tmp/chef-repo/cookbooks/motd! * template[/tmp/chef-repo/cookbooks/motd/metadata.rb] action create_if_missing! - create new file /tmp/chef-repo/cookbooks/motd/metadata.rb! - update content in file /tmp/chef-repo/cookbooks/motd/metadata.rb from none to 811b2e! (diff output suppressed by config)! * template[/tmp/chef-repo/cookbooks/motd/README.md] action create_if_missing! - create new file /tmp/chef-repo/cookbooks/motd/README.md! - update content in file /tmp/chef-repo/cookbooks/motd/README.md from none to 918996 142 Generate a “motd” cookbook
  • 143. $ tree #"" cookbooks! $   #"" motd! $   $   #"" Berksfile! $   $   #"" chefignore! $   $   #"" metadata.rb! $   $   #"" README.md 143 Examine motd cookbook
  • 144. Lab 4 - Manage Data & Policy Separately • Required steps: ✔️ Create a repository to store our cookbooks ✔️ Create a cookbook • Separate policy from data 144
  • 145. $ cat ~/motd.rb >> ~/chef-repo/cookbooks/motd/recipes/default.rb 145 Copy your motd.rb
  • 146. OPEN IN EDITOR: ~/chef-repo/cookbooks/motd/recipes/default.rb #! # Cookbook Name:: motd! # Recipe:: default! #! # Copyright (c) 2015 The Authors, All Rights Reserved.! file "/etc/motd" do! content "Property of COMPANY NAMEn” ! action :create! mode "0644" ! owner "root" ! group "root"! end Update the recipe 146
  • 147. Which resource should we use? • cookbook_file • file • remote_file • template 147
  • 148. motd/! #"" Berksfile! #"" chefignore! #"" files! $   !"" default! $   !"" motd! #"" metadata.rb! #"" README.md! !"" recipes! !"" default.rb cookbook_file • A file stored in the cookbook contains the content of the file 148
  • 149. file "/etc/motd" do! content "Property of COMPANY NAME" ! action :create! mode "0644" ! owner "root" ! group "root"! end file • The content is described inline in the recipe 149
  • 150. remote_file "/etc/motd" do! source "http://bit.ly/motd"! action :create! mode "0644" ! owner "root" ! group "root"! end remote_file 150 • The file is stored in a remote location, such as on a webserver
  • 151. motd! #"" Berksfile! #"" chefignore! #"" metadata.rb! #"" README.md! #"" recipes! $   !"" default.rb! !"" templates! !"" default! !"" motd.erb template • A template in the cookbook is used to render the content of the file 151
  • 152. motd/templates/default/motd.erb! template • A template is a mix of static and dynamic content 152 Property of <%= @company_name %>!
  • 153. Which resource should we use? • cookbook_file - static file within the cookbook • file - content managed inline • remote_file - static file obtained from URL • template - dynamic content rendered from ERB 153
  • 154. template • An ERB template stored as part of our cookbook 154
  • 155. OPEN IN EDITOR: ~/chef-repo/cookbooks/motd/recipes/default.rb #! # Cookbook Name:: motd! # Recipe:: default! #! # Copyright (c) 2015 The Authors, All Rights Reserved.! template "/etc/motd" do! source "motd.erb" ! action :create! mode "0644" ! owner "root" ! group "root"! end Update the recipe 155
  • 156. $ chef generate template --help Usage: chef generate template [path/to/cookbook] NAME [options]! -C, --copyright COPYRIGHT Name of the copyright holder - defaults to 'The Authors'! -m, --email EMAIL Email address of the author - defaults to 'you@example.com'! -a, --generator-arg KEY=VALUE Use to set arbitrary attribute KEY to VALUE in the code_generator cookbook! -I, --license LICENSE all_rights, apache2, mit, gplv2, gplv3 - defaults to all_rights! -s, --source SOURCE_FILE Copy content from SOURCE_FILE! -g GENERATOR_COOKBOOK_PATH, Use GENERATOR_COOKBOOK_PATH for the code_generator cookbook! --generator-cookbook 156 How do we generate a template?
  • 157. $ cd ~/chef-repo! $ chef generate template cookbooks/motd motd -s /etc/motd Compiling Cookbooks...! Recipe: code_generator::template! * directory[cookbooks/motd/templates/default] action create! - create new directory cookbooks/motd/templates/default! * file[cookbooks/motd/templates/default/motd.erb] action create! - create new file cookbooks/motd/templates/default/motd.erb! - update content in file cookbooks/motd/templates/default/motd.erb from none to 166ed9! (diff output suppressed by config) 157 Create the ERB template
  • 158. $ tree $   $   #"" templates! $   $   $   !"" default! $   $   $   !"" motd.erb 158 Examine cookbook
  • 159. OPEN IN EDITOR: ~/chef-repo/cookbooks/motd/templates/default/motd.erb Property of COMPANY NAME Check the template 159
  • 160. chef-apply • chef-apply does not understand cookbooks, only resources and recipes • We cannot use chef-apply to apply the policy stored in our motd cookbook 160
  • 161. chef-client • chef-client is an executable • performs all actions required to bring a node into the desired state • typically runs on a regular basis • daemon • cron • Windows service • Included with ChefDK 161
  • 165. chef-client applying policies 165 chef-client What policy should I follow? Test & Repair Apply the policy
  • 166. chef-client applying policies 166 chef-client What policy should I follow? Test & Repair Apply the policy
  • 167. chef-client applying policies 167 chef-client What policy should I follow? Test & Repair Apply the policy chef-client
  • 168. chef-client applying policies 168 chef-client What policy should I follow? Test & Repair Apply the policy chef-client What policy should I follow?
  • 169. chef-client applying policies 169 chef-client What policy should I follow? Test & Repair Apply the policy chef-client What policy should I follow? Test & Repair Apply the policy
  • 170. chef-client modes • In conjunction with a Chef Server • Local mode (no Chef Server) 170
  • 171. chef-client privileges • Usually run with elevated privileges • root • sudo • Administrator • Can run as non-privileged user 171
  • 172. $ cd ~/chef-repo! $ chef-client --local-mode -r “recipe[motd::default]”! $ chef-client --local-mode -r “recipe[motd]”! $ chef-client --local-mode -r “recipe[motd::weather]" 2015-01-11T11:05:00+00:00] WARN: No config file found or specified on command line, using command line options.! Starting Chef Client, version 11.18.0.rc.1! resolving cookbooks for run list: ["motd"]! Synchronizing Cookbooks:! - motd! Compiling Cookbooks...! Converging 0 resources! ! Running handlers:! Running handlers complete! Chef Client finished, 0/0 resources updated in 3.99531239 seconds 172 Apply our recipe using chef-client
  • 173. Pop Quiz • Why did chef-client update zero resources? 173
  • 174. Pop Quiz • Why did chef-client update zero resources? ! • Resources test & repair • Remember: we generated the template from an existing file on the filesystem • The content of /etc/motd is already the content we wanted 174
  • 175. chef-client applying policies recipe[motd] 175 chef-client What policy should I follow? Test & Repair Apply the policy recipe[motd]
  • 176. Lab 4 - Manage Data & Policy Separately • Required steps: ✔️ Create a repository to store our cookbooks ✔️ Create a cookbook ✔️ Separate policy from data 176
  • 177. Separating data from policy • Storing file content directly in a recipe is not typically the best choice • We can manage that content separately using a different resource • cookbook_file • remote_file • template 177
  • 178. Template resources • An ERB template that generates files based on a mix of static content along with variables and logic to determine dynamic content • If in doubt, start with a template 178
  • 179. What if…? • The contents of the motd file should be pulled from a file in an S3 bucket? • The motd file should have variable content based on different owners using the same cookbook? 179
  • 180. Summary • What components can be in a cookbook? • What program should we use to apply code from cookbooks? • What resource should we look to first when managing a file? 180
  • 181. Summary • What questions can I answer for you? 181
  • 182. AWS PopUp Loft - A Taste of Chef v2.0.0 Creating a simple web server 182 An Example Policy
  • 183. Lab 5 - Install an Apache webserver • The Problem: We need a web server configured to serve up a custom home page ! • Success Criteria: We can see the custom homepage in a web browser 183
  • 184. Required steps • Install Apache • Write out the home page • Start the Apache service • Make sure the Apache service starts when the machine boots • Stop and disable the iptables service ! • Please note we're teaching Chef primitives, not web server management! This is probably not the Apache HTTP server configuration you would use in production. 184
  • 185. $ cd ~/chef-repo! $ chef generate cookbook cookbooks/webserver Create a new webserver cookbook Compiling Cookbooks...! Recipe: code_generator::cookbook! * directory[/root/chef-repo/webserver] action create! - create new directory /root/chef-repo/webserver! - restore selinux security context! * template[/root/chef-repo/webserver/metadata.rb] action create_if_missing! - create new file /root/chef-repo/webserver/metadata.rb! - update content in file /root/chef-repo/webserver/metadata.rb from none to 4c0e2d! (diff output suppressed by config)! - restore selinux security context! * template[/root/chef-repo/webserver/README.md] action create_if_missing! - create new file /root/chef-repo/webserver/README.md! - update content in file /root/chef-repo/webserver/README.md from none to 5c3d3a! (diff output suppressed by config)! - restore selinux security context! * cookbook_file[/root/chef-repo/webserver/chefignore] action create! - create new file /root/chef-repo/webserver/chefignore! - update content in file /root/chef-repo/webserver/chefignore from none to 9727b1! (diff output suppressed by config)! - restore selinux security context 185
  • 186. OPEN IN EDITOR: ~/chef-repo/cookbooks/webserver/recipes/default.rb #! # Cookbook Name:: webserver! # Recipe:: default! #! # Copyright (c) 2015 The Authors, All Rights Reserved. Exercise: Edit the default recipe 186
  • 187. Which resource should we use? • Install Apache • Write out the home page • Start the Apache service • Make sure the Apache service starts when the machine boots • Stop and disable the iptables service 187
  • 188. Which resource should we use? • Install Apache • Write out the home page • Start the Apache service • Make sure the Apache service starts when the machine boots • Stop and disable the iptables service 188
  • 189. 3 most common resources - PST • Install software (package) • Manipulate files (template) • Manipulate services (service) ! • You will see this pattern very often 189
  • 190. • Install Apache - the package is named “httpd” • Write out the home page - /var/www/html/index.html • Manage the apache service - named “httpd” • Make sure the service is started • Make sure the service is enabled to start on boot • Manage the iptables service - named “iptables” • Make sure the service is stopped • Make sure the service is disabled to start on boot ! 190 Lab 5 - Install an Apache webserver
  • 191. #! # Cookbook Name:: webserver! # Recipe:: default! #! # Copyright (c) 2015 The Authors, All Rights Reserved.! ! package "httpd"! ! service "httpd" do! action [ :enable, :start ]! end! ! template "/var/www/html/index.html" do! source "index.html.erb"! end! ! service "iptables" do! action [ :disable, :stop ]! end Checkpoint - Lab 5 OPEN IN EDITOR: 191 ~/chef-repo/cookbooks/webserver/recipes/default.rb
  • 192. $ cd ~/chef-repo! $ chef generate template cookbooks/webserver index.html Create a template for index.html Compiling Cookbooks...! Recipe: code_generator::cookbook! * directory[/root/chef-repo/webserver] action create! - create new directory /root/chef-repo/webserver! - restore selinux security context! * template[/root/chef-repo/webserver/metadata.rb] action create_if_missing! - create new file /root/chef-repo/webserver/metadata.rb! - update content in file /root/chef-repo/webserver/metadata.rb from none to 4c0e2d! (diff output suppressed by config)! - restore selinux security context! * template[/root/chef-repo/webserver/README.md] action create_if_missing! <html>! - create new file /root/chef-repo/webserver/README.md! - update content in file /root/chef-repo/webserver/README.md from none to 5c3d3a! (diff output suppressed by config)! - restore selinux security context! * cookbook_file[/root/chef-repo/webserver/chefignore] action create! - create new file /root/chef-repo/webserver/chefignore! - update content in file /root/chef-repo/webserver/chefignore from none to 9727b1! (diff output suppressed by config)! - restore selinux security context 192
  • 193. OPEN IN EDITOR: <html>! <body>! <h1>Hello, World!</h1>! </body>! </html> 193 Checkpoint - Lab 5 ~/chef-repo/cookbooks/webserver/template/default/index.html.erb
  • 194. Question: does it work??? • This is a great opportunity for test-driven development • TDD is a way to automatically verify that your automation is producing expected results • Test against cheap throwaway infrastructure • e.g. inside containers! 194
  • 195. $ cd ~/chef-repo! $ sudo chef-client -z -r "recipe[webserver]" Recipe: webserver::default! * package[httpd] action install! - install version 2.2.15-39.el6.centos of package httpd! * service[httpd] action enable! - enable service service[httpd]! * service[httpd] action start! - start service service[httpd]! * template[/var/www/html/index.html] action create! - create new file /var/www/html/index.html! - update content in file /var/www/html/index.html from none to e043d5! --- /var/www/html/index.html! 2015-01-11 12:05:11.281712169 +0000! +++ /tmp/chef-rendered-template20150111-7749-3tgp7p! 2015-01-11 12:05:11.283712169 +0000! @@ -1 +1,6 @@! + <h1>Hello, World!</h1>! - restore selinux security context! * service[iptables] action disable! - disable service service[iptables]! * service[iptables] action stop! - stop service service[iptables]! Running handlers:! Running handlers complete! Chef Client finished, 6/6 resources updated in 13.854983543 seconds 195 Apply our recipe using chef-client
  • 196. $ curl http://localhost <html>! <body>! <h1>Hello, World!</h1>! </body>! </html> 196 Display your custom homepage
  • 197. Try it in a web browser 197
  • 198. $ chef-client --local-mode -r "recipe[webserver]" Starting Chef Client, version 11.18.0.rc.1! resolving cookbooks for run list: ["webserver"]! Synchronizing Cookbooks:! - webserver! Compiling Cookbooks...! Converging 4 resources! Recipe: webserver::default! * package[httpd] action install (up to date)! * service[httpd] action enable (up to date)! * service[httpd] action start (up to date)! * template[/var/www/html/index.html] action create (up to date)! * service[iptables] action disable (up to date)! * service[iptables] action stop (up to date)! ! Running handlers:! Running handlers complete! Chef Client finished, 0/6 resources updated in 7.046113816 seconds 198 Run chef-client again
  • 199. chef-client applying policies 199 chef-client What policy should I follow? Test & Repair Apply the policy recipe[webserver] recipe[webserver] Everything is up to date!
  • 200. Test & Repair • Gives you the ability to roll out new policies • Helps avoid unintended changes being made to the system • Prevent manual change • Prevent natural process of configuration drift • Encourage a culture of capturing all configuration 200
  • 201. Lab 6 - Display custom node data • The Problem: We want our home page to display the hostname of our node ! • Success Criteria: We can see the hostname of our node in a web browser 201
  • 202. How do we get our node name? • We could hard code the hostname of our node • That’s a bummer because it doesn’t scale • chef-client keeps a record of every node it manages • We should be able to get the name of any node managed by chef-client dynamically • We can use the knife tool to view this chef-client data 202
  • 203. knife • is an executable program used from the command line to communicate with a Chef server • can be used in local mode to mock Chef server functionality • in local-mode is a great way to explore some Chef server functionality without committing to running a Chef server just yet • is included as a part of the ChefDK 203
  • 204. $ knife node list --local-mode List nodes we know about WARNING: No knife configuration file found! ip-172-31-25-147.us-west-2.compute.internal! 204
  • 205. Node data from chef-client • chef-client saves a node object at the end of a run • In server mode, the Chef Server can be queried for information about the node • In local mode, the node object is saved to the local filesystem • A lot of this information comes from Ohai - we'll see Ohai later..... 205
  • 206. chef-client on our local vm • We have a node record for our workstation because we ran chef-client locally ! • Again, this sort of recursive management is not the way you’d do it in Production 206
  • 207. Each node must have a unique name • Every node Chef knows about must have a unique name within an organization • Chef defaults to the Fully Qualified Domain Name of the server, i.e. in the format server.domain.com • In EC2, this typically defaults to something that looks like ip-x-x-x-x.region.compute.internal 207
  • 208. $ knife node show ip-172-31-25-147.us-west-2.compute.internal --local-mode Show node details with knife WARNING: No knife configuration file found! Node Name: ip-172-31-25-147.us-west-2.compute.internal! Environment: _default! FQDN: ip-172-31-25-147.us-west-2.compute.internal! IP: 172.31.25.147! Run List: recipe[webserver]! Roles:! Recipes: webserver, webserver::default! Platform: centos 6.5! Tags: 208
  • 209. Pro-Tip: use $(hostname -f) • We can get our node’s Fully Qualified Domain Name in the right format using the hostname command • hostname -f returns the full FQDN 209
  • 210. $ knife node show $(hostname -f) --local-mode Show node details with knife WARNING: No knife configuration file found! Node Name: ip-172-31-25-147.us-west-2.compute.internal! Environment: _default! FQDN: ip-172-31-25-147.us-west-2.compute.internal! IP: 172.31.25.147! Run List: recipe[webserver]! Roles:! Recipes: webserver, webserver::default! Platform: centos 6.5! Tags: 210
  • 211. What is the Node object • Nodes are made up of Attributes • Many are discovered automatically (platform, ip address, number of CPUs) • Many other objects in Chef can also add Node attributes (Cookbooks, Roles and Environments, Recipes, Attribute Files) 211
  • 212. Where is the Node object • In server mode, node objects are stored and indexed on the Chef Server • In local mode, node objects are stored on the local filesystem ! • Node objects are stored in JSON 212
  • 213. $ ls ~/chef-repo/nodes List existing node objects ip-172-31-25-147.us-west-2.compute.internal.json 213
  • 214. $ less ~/chef-repo/nodes/$(hostname -f).json Peek inside the node object {! "name": "ip-172-31-7-47.us-west-2.compute.internal",! "normal": {! "tags": [! ! ]! },! "automatic": {! "keys": {! "ssh": {! "host_dsa_public": "AAAAB3NzaC1kc3MAAACBAIKx4i9XbyCQVvt2vStlkgNwLhHm5+kRHN3z! 5s8q+zseajCk+OxVoMzWAY4fj/5UOXpmZ2IJuGMF21RouO7HcZorNxOK5Y/1ABOUHec3NdZKBuPJcR14774F! r2UpMFu5ugPlA0w+jgsS4HygHAharE2o5EFFrH9v09Pc0OTYqhpxAAAAFQDHEr5ZDB1Jze5Vc5hokWNKxkrS! XwAAAIAudW/pKR9Dh0G4GqfW5hXdav/4tPQswvWpWorlThvlHTGfGnd8/W09jKFfTT/YMwqtvBLBqXbQApH6! kCMa8SfNXVJwpi6TTusRTV2MJrPSp/lnJ3Ya/Qan/QFvI+axgTmhh9qZNEp9LiUzyOHrjLsoP8K38JX89A1j! 5gIFjw4gZgAAAIAWRjt7EuD3S+rdkzqzWiXXy8t8taLMednUqV1cpweWg6nKzcIkoEG5r4Anp7VYatTaG9Ur! cR1XzCFsVgFULKA42r1skz1u8XLwZVhFR57j4A+NqyEiN17LHzPeQ/sfEVrZ67zWqkaxF3EdsqFMH1zhoE0q! IZYGjOwTg6jbgIEiDw==", 214
  • 215. Where does this data come from? • Ohai is a discovery agent included with Chef • It is executed every single time chef-client is run • Extensible plugin model allows custom data • Chef uses some information (e.g. platform ) to make decisions about how to implement resources 215
  • 216. Package Resource package "git" { yum install git ! apt-get install git ! pacman sync git ! pkg_add -r git Providers aredetermined! by node's platform 216
  • 217. Ohai "languages": {! "ruby": {! ! },! "perl": {! "version": "5.14.2",! "archname": "x86_64- linux-gnu-thread-multi"! },! "python": {! "version": "2.6.6",! "builddate": "Jul 10 2013, 22:48:45"! },! "perl": {! "version": "version",! "archname": "x86_64- linux-thread-multi"! },! "lua": {! "version": "5.1.4"! }, "network": {! "interfaces": {! "lo": {! "mtu": "16436",! "flags": [! "LOOPBACK", "UP","LOWER_UP"! ],! "encapsulation": "Loopback",! "addresses": {! "127.0.0.1": {! "family": "inet",! "netmask": "255.0.0.0",! "scope": "Node"! },! "::1": {! "family": "inet6",! "scope": "Node"! }! },! },! "eth0": {! "type": "eth",! "number": "0", "kernel": {! "name": "Linux", ! "release": "3.2.0-32-virtual",! "version": "#1 SMP Wed Oct 16 18:37:12 UTC 2013",! "machine": "x86_64",! "modules": {! "isofs": {! "size": "70066",! "refcount": "2"! },! "des_generic": {! "size": "16604",! "refcount": "0"! }! },! "os": "GNU/Linux"! },! "os": "linux",! "os_version": "2.6.32-358.23.2.el6.x86_64",! "ohai_time": 1389105685.7735305, 217
  • 218. $ ohai | more Run Ohai on node {! "languages": {! "ruby": {! "platform": "x86_64-linux",! "version": "2.1.4",! "release_date": "2014-10-27",! "target": "x86_64-unknown-linux-gnu",! "target_cpu": "x86_64",! "target_vendor": "unknown",! "target_os": "linux",! "host": "x86_64-unknown-linux-gnu",! "host_cpu": "x86_64",! "host_os": "linux-gnu",! "host_vendor": "unknown",! "bin_dir": "/opt/chefdk/embedded/bin",! "ruby_bin": "/opt/chefdk/embedded/bin/ruby",! 218
  • 219. Node data • To Chef, your infrastructure is just large hashes of data stored as JSON • Much of that data comes from Ohai • e.g. The “languages” hash is detected via Ohai • Some of that data is generated during a chef-client run • e.g. node name is generated by chef-client • All of this data is indexed and available for search • When using a Chef Server, all of your infrastructure configuration data is aggregated in one central location 219
  • 220. $ knife node show $(hostname -f) --local-mode -a ipaddress Show specific attributes with knife WARNING: No knife configuration file found! ip-172-31-7-47.us-west-2.compute.internal:! ipaddress: 172.31.7.47 220
  • 221. $ knife node show $(hostname -f) --local-mode -a cpu.0.model_name Show specific attributes with knife WARNING: No knife configuration file found! ip-172-31-7-47.us-west-2.compute.internal:! cpu.0.model_name: Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz 221
  • 222. $ knife node show $(hostname -f) --local-mode -a name Show specific attributes with knife WARNING: No knife configuration file found! ip-172-31-25-147.us-west-2.compute.internal:! name: ip-172-31-25-147.us-west-2.compute.internal 222
  • 223. OPEN IN EDITOR: <html>! <body>! <h1>Hello from <%= node.name %></h1> ! </body>! </html> 223 Include node name in the index.html template ~/chef-repo/cookbooks/webserver/templates/default/index.html.erb
  • 224. $ chef-client --local-mode -r "recipe[webserver]" Compiling Cookbooks...! Converging 4 resources! Recipe: webserver::default! * package[httpd] action install (up to date)! * service[httpd] action enable (up to date)! * service[httpd] action start (up to date)! * template[/var/www/html/index.html] action create! - update content in file /var/www/html/index.html from e043d5 to c1d241! --- /var/www/html/index.html! 2015-01-11 12:05:11.283712169 +0000! +++ /tmp/chef-rendered-template20150111-8914-mzgycj! 2015-01-11 13:05:09.112712168 +0000! @@ -1,6 +1,6 @@! <html>! <html>! <body>! - <h1>Hello, World!</h1>! + <h1>Hello from ip-172-31-25-147.us-west-2.compute.internal! </body>! </html>! - restore selinux security context 224 Apply our recipe using chef-client
  • 225. Congratulations! 225 • You have just deployed a dynamic website!
  • 226. Summary • How is infrastructure referenced by Chef? • Where do we get most data in those JSON hashes? • Which three resources are the most commonly found resources in configuration management? 226
  • 227. Summary • What questions can I answer for you? 227
  • 228. AWS PopUp Loft - A Taste of Chef v2.0.0 Wrap Up 228 Recap & Next Steps
  • 229. Tool Survey • chef-apply • chef • chef-client in local mode • knife in local mode 229
  • 230. Vocabulary • Resources • Recipes • Cookbooks • Nodes 230
  • 231. Resources • Package • File • Template • Service 231
  • 232. Continued Learning • The LearnChef Site • Guided Tutorials • Chef Fundamentals intro http://learnchef.com • How-To’s, Conference Talks, Webinars, more http://youtube.com/user/getchef • Attend a Chef Fundamentals Class 232
  • 233. Further Resources • http://chef.io • http://docs.chef.io • http://supermarket.chef.io • http://lists.opscode.com • irc.freenode.net #chef • Twitter @chef #getchef, @learnchef #learnchef 233
  • 234. Chef Fundamentals (Local) • 2 Day Chef Fundamentals (San Francisco) • February 3-4, 2015, 9am-5pm • 2 Day Chef Fundamentals (San Francisco) • March 5-6, 2015, 9am-5pm ! • 25% OFF, use discount code: TSW25 234
  • 235. Food Fight Show • http://foodfightshow.org • The Podcast Where DevOps Chef Do Battle • Regular updates about new Cookbooks, Knife- plugins, and more • Best Practices for working with Chef 235