Home » Home » Opscode Chef Knife Commands

Chef is another Configuration Management Tool which is there in industry for years. Okay lets skip the topic of why chef, or why not puppet or ansible or CFengine or whatever. Every tool have their own pros and cons, based on the infrastructure which it suites.

In this article I’m going to give you basic knife and chef commands for beginners, and I’m not going to talk about setting up chef server or workstation. If you are a puppeter you can take a look at this article.

Knife Commands:

Knife command to bootstrap a node with setting a proxy

$ knife bootstrap <node name> -x <user name> –bootstrap-proxy <http://proxy> –bootstrap-no-proxy <http://no proxy ips>

Cookbook 

Knife command to run a cookbook on a node after bootstrap

$ knife bootstrap <node name> -r recipe[<cookbook name>]

Knife command to create cookbooks

$ knife cookbook create <cookbook-name>

Knife command to list all cookbooks

$ Knife cookbook list

Knife command do download a cookbook from check server

$ knife cookbook download  <cookbook name> <version>

Knife command to upload the cookbook to chef server

$ knife cookbook upload <cookbook-name>

knife command to show the cookbook info in json and save it to a file

$ knife cookbook show <cookbook name> -Fj > (cookbook name).json

knife command to delete cookbook from server

$ knife cookbook delete <cookbook name>

Node

Knife command to create node

$ knife node create <node name>

knife command to list all node in server

$ knife node list

knife command to get the node info in json and save it to a file

$ knife node show <node-name> -Fj > (node name).json

To run any shell command on the node

$ knife ssh -m <node name> <command>

Knife command to add a run list on a node

$ knife node run_list add <node name> recipe[<cookbookname>]

knife command to edit a node

$ knife node edit <node name>

Knife command to delete a node

$ knife node delete <node name>

Client

Knife command to create a client and save the pem key to a file

$ knife client create <client name>

Knife command to list all clients

$ knife client list

Knife command to edit the client info

$ knife client list <client name>

Knife command to save the client info to a json file

$ knife client show <client name> -Fj > (client name).json

Knife command to delete a client

$ Knife client delete <client name>

Environment

Knife command to create a environment

$ knife environment create <environment name>

Knife command to list environments

$ knife environment list

Knife command to edit environment

$ knife environment edit

Knife command to upload the environment json file to the server

$ knife environment from file <jason file name>

knife command to delete a environment

$ Knife environment delete <environment name>

Role

Knife command to create a role

$ knife role create <role name>

Knife command to list roles

$ knife role list

Knife command to edit role

$ knife role edit

Knife command to upload the role json file to the server

$ knife role from file <json file name>

knife command to delete a role

$ Knife role delete <role name>

knife kitchen <name>

Chef client commands:

Chef command to run a cookbook in client without knife

$ chef-client -o “recipe[<cookbook name>]”

Chef command to run a cookbook in debug mode

$ chef-client -o “recipe[<cookbook name>]” -l debug

Chef command to run a recipe

$ chef-client -o “recipe[<cookbook name>::<recipe rbfile>]”

Check command to run a specific version of cookbook

$ chef-client -o “recipe[<cookbookname>@<version>]”

All these commands are essential for basic chef learning, I have just drafted this post only with the commands I have been used, there are lot of other knife and chef commands available, use knife help and search to find it out.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA Image

*