Chef : Creating and Using Cookbooks on VirtualBox node
This chapter is not complete. I got an error at chef-client to bring the node into the expected state. So, this needs to be fixed.
Cookbooks are an essential part of Chef. We can easily create them using Knife.
In this chapter, we'll create and apply a simple cookbook using Knife.
We need to make sure Chef has been installed and a node available for testing.
Knife is a command-line interface for the Chef Server. It uses the RESTful API exposed by the Chef Server to do its work and provides us to interact with the Chef Server. In other words, knife provides an interface between a local chef-repo and the Chef server.
The knife command supports a host of commands structured like this:
In this chapter, we'll use two primary knife commands:
- knife cookbook create : to create a new cookbook directory on the local machine, including the sub-directories and files.
- knife cookbook upload : to upload one or more cookbooks (and any files that are associated with those cookbooks) from a local repository to the Chef server. Only files that do not already exist on the Chef server will be uploaded.
- knife node run_list add : to add run-list items (roles or recipes) to a node. A run-list defines all of the configuration settings that are necessary for a node that is under management by Chef to be put into the desired state.
In this section, we'll learn how to create and use cookbook.
- Create a cookbook by running the following with the name "bogo_cookbook":
k@laptop:~/chef-repo$ sudo knife cookbook create bogo_cookbook ** Creating cookbook bogo_cookbook ** Creating README for cookbook: bogo_cookbook ** Creating CHANGELOG for cookbook: bogo_cookbook ** Creating metadata for cookbook: bogo_cookbook
- Upload our new cookbook to the Chef Server:
k@laptop:~/chef-repo$ sudo knife cookbook upload bogo_cookbook Uploading bogo_cookbook [0.1.0] Uploaded 1 cookbook.
- Add the your node's run list. In our case, the name of the node
k@laptop:~/chef-repo$ sudo knife node run_list add hosted_server recipe[bogo_cookbook] hosted_server: run_list: recipe[bogo_cookbook]
- ssh to our box:
k@laptop:~/chef-repo$ vagrant ssh Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-40-generic i686) ...Run Chef Client on our node:
k@laptop:~/chef-repo$ vagrant ssh Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-40-generic i686) ... k@laptop:~/chef-repo$ sudo chef-clientAt this point, I got an error:
Networking Error: ----------------- Connection refused chef clientI need to comeback later to fix this error.
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization