Tuesday, 24 January 2017

Manage Chef with knife

Basic Chef Knife Commands

Knife Commands Usage

Knife is a command-line tool that comes by default with Chef DK that is Chef Development Kit. Knife provides an interface between your 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:

Create a new cookbook

knife cookbook create <cookbook_name>

Its recommended to use _ (underscore) in cookbook name instead of - (hyphen).

Upload a new or modified cookbook

knife cookbook upload <cookbook_name>

List all the nodes defined in Chef

knife node list

Show details about a node

knife node show <node_name> -l

Modify a existing node

knife node edit <node_name>

This command will open a default editor, to let you edit node details.

Add a node defined in a file to Chef

knife node from file <file_name>

List all roles

knife role list

Show details about a role

knife role show <role_name>

To query about particular role attribute value use -a option.

Add a role from a file

knife role from file <file_name>

Edit existing role

knife role edit <role_name>

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]"

Remove a role or recipe from a node

knife node run_list remove <node_name> "role[role_name]"

Bootstrap a new node with Chef

knife bootstrap <new-host-ip> -x root -P password -N <node_name>

Enjoy chef with knife!

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel