Quick Notes

Things that came on the way

Basic Chef Knife Commands

While using any tool, 80% of all work is accomplished by very small percentage of commands available. Following are some of the commonly used Chef Knife commands.

  • To create a new cookbook
1
knife cookbook create cookbook_name

Note: use underscore instead of “-” (hyphen) in cookbook names. Hypen seem to prevent identification of LWRPs included in the cookbook.

  • To upload a new or modified cookbook
1
knife cookbook upload cookbook_name
  • To list all the nodes currently defined in Chef
1
knife node list
  • To show details about a node
1
knife node show node_name -l

Note: -l option generates a detailed list of properties about the node. Leaving it out will generate a summary about the node. Use -a option to query about a particular node attribute

  • To edit a new node or modifying an existing node
1
knife node edit node_name

This will let you edit the node details using the default editor set

  • To add a node defined in a file to Chef
1
knife node from file file_name
  • To list all the roles defined in Chef
1
knife role list
  • To show details about a role
1
knife role show role_name

Use -a option to query about a particular role attribute value

  • To add a role from a file
1
knife role from file file_name
  • To edit a new or existing role
1
knife role edit role_name
  • To add a role or recipe to a node
1
2
3
knife node run_list add node_name "recipe[cookbook::recipe]"
knife node run_list add node_name "role[role_name]"
knife node run_list add node_name "role[role_name],recipe[cookbook::recipe]"
  • To remove role or recipe from a node use “remove” instead of “add”
1
knife node run_list remove node_name "role[role_name]"
  • To bootstrap a new node with Chef
1
knife bootstrap new-host-ip -x root -P password -N node_name

Happy Cheffing!!

Comments