Permalink
Browse files

additional modification from peer review with Stephen

  • Loading branch information...
1 parent 936d389 commit 6b1888cd6b96ca87463deee6b7e47ff08a026715 @jtimberman jtimberman committed Feb 19, 2012
@@ -23,7 +23,7 @@ Upload the `webserver` role to the Chef Server.
## Modify Node
-Use `knife` to remove the `fail2ban` recipe from the node's run list
+Use `knife` to remove the `webserver` recipe from the node's run list
and add the `webserver` role.
Re-run `chef-client` on the node.
@@ -1,13 +1,4 @@
Troubleshooting
======================
-The instructor will lead the students through interactive
-troubleshooting exercises.
-
-## Objectives
-
-* Work with Chef's logger
-* Debug Chef's stack traces
-* Recognize HTTP status codes from the Chef Server
-* Gracefully handle errors in recipes
-* Understand Chef's exception handlers
+Opportunities to troubleshoot will present themselves throughout the course.
@@ -20,6 +20,8 @@ The order is structured by level of general interest.
We will not have time to cover these in great detail. See the
__Additional Resources__ list for more details.
+We may not have time to cover them all entirely.
+
This section does not have a hands on exercise.
# Questions
@@ -30,7 +32,8 @@ Answer outstanding questions from earlier sections.
Data bags are containers of "items" that are plain JSON data.
-Items can contain any arbitrary key/value pairs, such as user information, application setup parameters or DNS entries.
+Items can contain any arbitrary key/value pairs, such as user
+information, application setup parameters or DNS entries.
They are centrally available to recipes for processing.
@@ -62,6 +65,7 @@ common use cases we practice or have seen:
* Application information
* Hardware inventory
* Authentication credentials
+
# Encrypted Data Bags
Data bags can be encrypted with a secret key.
@@ -85,7 +89,7 @@ You probably already had a key distribution problem (think SSL).
"comment": "USERNAME",
"uid": 2003,
"shell": "/bin/bash",
- "ssh_keys": "ssh-rsa SSH_PUBLIC_KEYp USERNAME@localhost"
+ "ssh_keys": "ssh-rsa SSH_PUBLIC_KEY USERNAME@localhost"
}
> knife data bag create users
> knife data bag from file users USERNAME.json
@@ -99,6 +103,9 @@ Search can be done just like nodes or roles with knife or in a recipe.
knife search BAG QUERY
search(:bag, "QUERY")
+Encrypted data bags cannot be searched because the contents are...
+encrypted.
+
# Search Data Bags: Knife
> knife search users "id:USERNAME"
@@ -159,18 +166,17 @@ Version constraints can use operators to determine the version.
< Less than
>= Greater than or equal to
<= Less than or equal to
- ~> Approximately greater than
- "~> 2.6" matches cookbooks >= 2.6.0 AND < 3.0.0
- "~> 2.6.5" matches cookbooks >= 2.6.5 AND < 2.7.0
+Advanced operators are available similar to those of RubyGems, see the
+Version Constraint documentation.
# Example Environment
name "production"
description "Systems in production"
cookbook_versions(
"apache2" => "1.0.8",
- "mysql" => "1.0.0"
+ "mysql" = "1.0.0"
)
# Environments: Nodes
@@ -289,6 +295,7 @@ Cloud Computing providers like Amazon EC2.
* http://wiki.opscode.com/display/chef/Data+Bags
* http://wiki.opscode.com/display/chef/Environments
+* http://wiki.opscode.com/display/chef/Version+Constraints
*
http://wiki.opscode.com/display/chef/Lightweight+Resources+and+Providers+%28LWRP%29
* http://wiki.opscode.com/display/chef/Knife+Plugins
@@ -55,8 +55,8 @@ Open training materials are Creative Commons licensed and released periodically.
* Version 1 is from April 2010.
* Version 2 were used but not released.
-* Version 3 is current, this version.
-* Version 4 is under development.
+* Version 3 is the last version in Keynote/PDF.
+* Version 4 is current, this version.
Sign up on the web site for updates.
@@ -84,6 +84,13 @@ Announcements of upcoming events are posted to our blog and twitter ([@opscode](
* http://community.opscode.com
+# ChefConf
+
+Our first Chef users' conference is May 15-17, 2012, in Burlingame,
+CA.
+
+* http://chefconf.opscode.com
+
# Plugins and RubyGems
Many other people are creating plugins and RubyGems for Chef and Knife.
@@ -200,6 +200,8 @@ We can also use node attributes directly.
Node attributes used in a template can come from the cookbook itself,
or one auto detected by chef such as "platform".
+.notes We do *not* need to use the `@` symbol on the node.
+
# Cookbook Attributes
Node attributes can come from cookbooks.
@@ -341,7 +343,7 @@ Retrieve the value of the node's environment with the
@@@ruby
node.chef_environment # => "_default"
-We will discuss Chef Environments in more detail later.
+We will discuss Chef Environments later.
# Examining Chef::Node
@@ -88,17 +88,17 @@ Included recipes from other cookbooks require metadata dependency.
# Cookbook Dependencies
-Cookbook dependencies are implied when using part(s) of one cookbook
-in another, such as recipe inclusion.
+Remember, cookbook dependencies are assumed when using part(s) of one
+cookbook in another, such as recipe inclusion.
+
+Cookbook dependencies are explicitly defined in metadata. Use the
+"depends" keyword. This will cause Chef to download the dependency
+cookbook from the server.
Downloading a cookbook as a dependency from another does not cause it
to be applied on the node. It merely makes the code/contents available
for another cookbook to use it.
-Cookbook dependencies are explicitly defined in metadata.
-
-Use the "depends" keyword in the metadata.
-
# Cookbook Metadata
The metadata defines the additional cookbooks required that might not
@@ -191,6 +191,9 @@ Download the haproxy cookbook.
> knife cookbook site download haproxy
> tar -zxvf haproxy-1.0.4.tar.gz -C cookbooks
+We will explore the haproxy cookbook for this pattern because we'll
+revisit it in the next section on search.
+
# haproxy default recipe
The default recipe follows the pattern.
@@ -21,7 +21,7 @@ The search query language is modified SOLR Lucene.
# Default Search Indexes
-Four search indexes are created by default.
+Four search indexes are created on the Chef Server by default.
* node
* client
@@ -112,40 +112,50 @@ Search for all nodes that have 2 CPUs or are 64bit.
# Recipe Search
-Two kinds of search can be used in recipes.
+You can run a search and retrieve the results, assigning them to a
+local variable.
-* Aggregated
-* Block
+Or, you can run a search and iterate over the results dynamically.
-# Aggregate Search Results
+# Assign Results to Variable
- pool = search("node", "role:webserver")
+ pool = search(:node, "role:webserver")
-Results can be aggregated and assigned to a local variable for later
-processing in a recipe.
+`pool` will be an array of the JSON representation of all the node
+objects that match the search.
-The entire JSON object from the server is returned.
+We can then use this node data in the recipe to configure resources
+dynamically.
.notes that the entire object is returned in the results can be a
significant use of system memory
-# Aggregate Results: Collect Values
+# Assign Results to Variable
+
+Sometimes we only want specific attributes of nodes that match the
+search query. As the `search` results are an array, we can generate
+another array based on a specific condition using the `#map` method
+(from Enumerable).
ip_addrs = search(:node, "role:webserver").map {|n| n["ipaddress"]}
-Aggregated results can be passed a Ruby block with the "map" method
-and the value of a single attribute can be extracted.
+`ip_addrs` will be an array of the `ipaddress` attribute from all the
+node objects that match the search. Contrast to `pool` from before which
+contained the entire node objects.
+
+# Iterating Over a Search
-# Block Search
+We can iterate over the search results in real time because search
+takes a block as a parameter.
@@@ruby
search(:node, "role:webserver") do |match|
puts match["ipaddress"]
end
-Provide a code block to process the results directly.
-
-We'll see this more with Data Bags.
+Provide a Ruby block to process the results directly. We could do
+other things such as creating a resource for each result and pass the
+data from the objects returned into the resource's paramter attributes.
# Common Search Usage
@@ -164,6 +174,20 @@ Knife has two built in subcommands that use search.
* knife status
* knife ssh
+# Knife Status
+
+Knife's status subcommand performs a search and prints out information
+about all the nodes, e.g.:
+
+ > knife status
+ 1 hour ago, www1, www1.example.com, 10.1.1.20, ubuntu 10.04.
+ 1 hour ago, www2, www2.example.com, 10.1.1.21, ubuntu 10.04.
+
+By default it searches for all the nodes, but you can pass it a
+query like with knife search.
+
+ > knife status "role:webserver"
+
# Bootstrapping Chef
The process of installing and initially running Chef is referred to as
@@ -215,6 +239,9 @@ The
(chef-full, as of Chef 0.10.10+) will install the Chef Full Stack package that we
have been using. Other bootstrap templates are available.
+.notes Chef 0.10.10 may not be released yet, which means we can
+retrieve the raw file directly from the internets and run it as root.
+
# Knife Bootstrap Customization
The bootstrap "templates" are really just shell scripts.
Oops, something went wrong.

0 comments on commit 6b1888c

Please sign in to comment.