Learning Knife To Manage Chef | Tutorial
Knife Command Cheat-sheet
To manage chef there is a command line tool known as Knife. It comes by default with Chef Development kit. It acts as an interface between local chef repo and chef-server. Basically Knife helps with managing:
- Cookbooks and recipes
- Nodes
- Roles
- Stores of JSON data (including encrypted version)
- Environment
- Cloud Resources and provisioning
- Installation of chef-client on workstation
- Searching of indexed data on chef server
So example of usage of some basic Knife commands is as follow:
knife command to create a new cookbook
knife cookbook create <cookbook_name>
Its recommended to use _ (underscore) in cookbook name instead of – (hyphen).
Knife command to upload a new or modified cookbook
knife cookbook upload <cookbook_name>
Knife command to list all the nodes defined in Chef
knife node list
Knife command to show details of a node
knife node show <node_name> -l
Knife command to modify a existing node
knife node edit <node_name>
This command will open a default editor, to let you edit node details.
Knife command to add a node defined in a file to Chef
knife node from file <file_name>
Knife command to list all roles
knife role list
Knife command to show details about a role
knife role show <role_name>
To query about particular role attribute value use -a option.
Knife command to add a role from a file
knife role from file <file_name>
Knife command to edit existing role
knife role edit <role_name>
Knife command to add a role or recipe to a node
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]”
Knife command to remove a role or recipe from a node
knife node run_list remove <node_name> "role[role_name]"
Knife command to bootstrap a new node with Chef
knife bootstrap <new-host-ip> -x root -P password -N <node_name>