How to install and configure knife


In this article I will show you how to install and configure the knife application that is used to interact with the chef 12 server that we’ve created in a past article.

The first thing you’ll have to do is install the chef package by running the following command:

yum install -y chef

Wait for the installation to finish before proceeding further. Note that I’ve created my own yum repository in which I’ve saved the necessary package. If you don’t have a yum repository you can download the package locally and use the following command to install it:

rpm -Uvh chef-12.10.24-1.el6.x86_64.rpm

Once the package has been successfully installed, navigate to your user’s home directory. Note that you have to create the user account on the chef server. Please check out the last chef article before proceeding further if you don’t already have the user account and the organization created in the chef server.

Now create a directory .chef by using the mkdir .chef command.

Copy the validation file of the chef organization and the user account .pem file in this location. Create a file named knife.rb and add the following lines within it:

[root@Centos06-1 .chef]# cat knife.rb
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name “root”
client_key “/root/.chef/root.pem”
validation_key “/root/.chef/ppscu-validator.pem”
chef_server_url “https://ChefserverURL/organizations/ppscu”
cookbook_path [“/opt/chef-repo/cookbooks”]
ssl_verify_mode [:verify_none]
verify_api_cert “false”

The important lines that must be edited are: node_name, client_key, validation_key, chef_server_url and cookbook_path. Save the file and exit the text editor.

Note that if the chef_server_url has been configured correctly you should now be able to interact with the chef server.

Use the knife node list or knife environment list to verify that you can interact with the server. Note that if you receive any ssl errors, use the knife ssl fetch and knife ssl check commands to fix the issue.

You should now have knife application installed and configured and you should also be able to interact with the chef server

Leave a comment