Overview
At this point, you should have completed the installation process and have a working Chef server.If you are using Hosted Chef, you can run these commands from the management workstation you've setup. Get a Chef RepositoryA Chef repository is just a directory structure where you keep your cookbooks and other files. If you haven't done so already, clone Opscode's Chef repository from github: Clone the Chef Repository from Opscode |
|
|
When you find a cookbook at the Community Site that you would like to use, you can use these steps to add it to the Chef Server/Hosted chef. Downloading the Cookbook, Uploading it to the Chef Server/Hosted ChefYou can use this command to download a new cookbook, substitute COOKBOOK for the name of the cookbook you want to download: Once this command completes, the cookbook will have been downloaded to the chef-repo directory, in the cookbooks folder. You can feel free to edit it if needed, then you can upload it to the Chef Server/Hosted Chef with this command: Now this cookbook will be available to add to a node's run_list. If you want to make any changes to it, just edit it from you workstation and upload it again to Chef Server/Hosted Chef. If you'd like some quick information on how to add this to a node's run_list you can find this in Step 3 of the Client Bootstrap Fast Start Guide guide. For more information on using cookbooks that are on the Community Site see the Cookbooks page. You can also create your own cookbooks, and upload these into the Chef Server/Hosted chef. The steps below go over creating a new cookbook named fast_start and running it on a node.
Create a new Cookbook called "fast_start"Change your working directory to the cookbooks/ directory of your Chef repository. If you cloned the repository into /tmp/sandbox/ as shown above: Now create the cookbook with knife cookbook create: Create the fast_start cookbook This will create the cookbook's directory structure: This cookbook is going to have a simple recipe that renders a simple text file using some Attributes we will define. Add an attribute file called "fast_start.rb"With your favorite text editor, create a file in cookbooks/fast_start/attributes called fast_start.rb, with the following contents. cookbooks/fast_start/attributes/fast_start.rb
Add a template resource to the default recipeNext, edit cookbooks/fast_start/recipes/default.rb and add the following: cookbooks/fast_start/recipes/default.rb Add the template file itselfIn the template resource we defined above, we referenced a source parameter. This is the actual template file, and it is placed in cookbooks/fast_start/templates/default/deep_thought.txt.erb. Lets create it now: cookbooks/fast_start/templates/default/deep_thought.txt.erb
Upload the Cookbook to the ServerYou should be keeping your cookbooks in version control, and you should start getting in the habit now, so commit your work using your favorite version control system. Now that your work is in version control, upload the cookbook to the server. Update the Cookbooks on the Chef Server The output will look like the following, though your file checksums will be different: Confirm that the server has the cookbook you just uploaded: Register a node with chef-clientFor this step, you'll need a new host to run chef-client. We recommend you use a virtual machine with snapshots for the maximum effectiveness when developing cookbooks. There is also a Client Bootstrap Fast Start Guide guide if you would prefer to set this up on a separate node. If you'd like to set up a VM, simply create it with the base OS of your choice and install chef client on it. We also recommend you take a snapshot of the VM in this pristine state—if trouble strikes, you'll be able to roll back and try again. Once you have chef-client installed on the host, you'll need to copy the validation key, /etc/chef/validation.pem, from your Chef server box to the same location on the chef-client box. The validation key is used by the chef-client as a temporary identity so it can register itself; after it registers it will have its own key in /etc/chef/client.pem ([read more about Chef's authentication system]). (If you don't have an /etc/chef/validation.pem or /etc/chef/client.rb generate them with knife configure client....) With the validation key in place, run chef client: Run chef-client Add the fast_start recipe to your new NodeFrom your management workstation (where you run knife from) run the knife node run_list add command. Use the name of the client machine for HOSTNAME (If you're not sure what to put here, check the output of knife node list). You can see that your change was made on the server using knife node show: Run chef-client again on your new Node.This time, executing chef-client will cause /tmp/deep_thought.txt to appear! Run chef-client If you run the command again, you'll notice that it does nothing at all, because the deep_thought.txt file has not changed, either on disk or on the Chef Server. Congratulations!You have just written your first Chef Cookbook! You'll be managing your entire infrastructure in no time! Chef BasicsLearn some of the central concepts of configuration management benefits for your infrastructure.
Chef ArchitectureWith all that under your belt, it's time to tackle the dirty secrets of what's happening behind the scenes with Chef Architecture. We'll give you the scoop on Chef's Authentication and Authorization system and go over the Anatomy of a Chef Run, where we go in-depth with the process by which your systems get configured. From there we'll review all the executable parts of Chef - Chef Client, Chef Solo, Chef Server, Chef Indexer, and Server API and Cookbook Site API interaction.
|
|
|


