Setup Knife in Chef

Last updated on Nov 12 2021
Satyen Sahu

Table of Contents

Setup Knife in Chef

Chef – Knife Setup

Knife is Chef’s command-line tool to interact with the Chef server. One uses it for uploading cookbooks and managing other aspects of Chef. It provides an interface between the chefDK (Repo) on the local machine and the Chef server. It helps in managing −

  • Chef nodes
  • Cookbook
  • Recipe
  • Environments
  • Cloud Resources
  • Cloud Provisioning
  • Installation on Chef client on Chef nodes

Knife provides a set of commands to manage Chef infrastructure.

Bootstrap Commands

  • knife bootstrap [SSH_USER@]FQDN (options)

Client Commands

  • knife client bulk delete REGEX (options)
  • knife client create CLIENTNAME (options)
  • knife client delete CLIENT (options)
  • knife client edit CLIENT (options)
  • Usage: C:/opscode/chef/bin/knife (options)
  • knife client key delete CLIENT KEYNAME (options)
  • knife client key edit CLIENT KEYNAME (options)
  • knife client key list CLIENT (options)
  • knife client key show CLIENT KEYNAME (options)
  • knife client list (options)
  • knife client reregister CLIENT (options)
  • knife client show CLIENT (options)

Configure Commands

  • knife configure (options)
  • knife configure client DIRECTORY

Cookbook Commands

  • knife cookbook bulk delete REGEX (options)
  • knife cookbook create COOKBOOK (options)
  • knife cookbook delete COOKBOOK VERSION (options)
  • knife cookbook download COOKBOOK [VERSION] (options)
  • knife cookbook list (options)
  • knife cookbook metadata COOKBOOK (options)
  • knife cookbook metadata from FILE (options)
  • knife cookbook show COOKBOOK [VERSION] [PART] [FILENAME] (options)
  • knife cookbook test [COOKBOOKS…] (options)
  • knife cookbook upload [COOKBOOKS…] (options)

Cookbook Site Commands

  • knife cookbook site download COOKBOOK [VERSION] (options)
  • knife cookbook site install COOKBOOK [VERSION] (options)
  • knife cookbook site list (options)
  • knife cookbook site search QUERY (options)
  • knife cookbook site share COOKBOOK [CATEGORY] (options)
  • knife cookbook site show COOKBOOK [VERSION] (options)
  • knife cookbook site unshare COOKBOOK

Data Bag Commands

  • knife data bag create BAG [ITEM] (options)
  • knife data bag delete BAG [ITEM] (options)
  • knife data bag edit BAG ITEM (options)
  • knife data bag from file BAG FILE|FOLDER [FILE|FOLDER..] (options)
  • knife data bag list (options)
  • knife data bag show BAG [ITEM] (options)

Environment Commands

  • knife environment compare [ENVIRONMENT..] (options)
  • knife environment create ENVIRONMENT (options)
  • knife environment delete ENVIRONMENT (options)
  • knife environment edit ENVIRONMENT (options)
  • knife environment from file FILE [FILE..] (options)
  • knife environment list (options)
  • knife environment show ENVIRONMENT (options)

Exec Commands

  • knife exec [SCRIPT] (options)

Help Commands

  • knife help [list|TOPIC]

Index Commands

  • knife index rebuild (options)

Node Commands

  • knife node bulk delete REGEX (options)
  • knife node create NODE (options)
  • knife node delete NODE (options)
  • knife node edit NODE (options)
  • knife node environment set NODE ENVIRONMENT
  • knife node from file FILE (options)
  • knife node list (options)
  • knife node run_list add [NODE] [ENTRY[,ENTRY]] (options)
  • knife node run_list remove [NODE] [ENTRY[,ENTRY]] (options)
  • knife node run_list set NODE ENTRIES (options)
  • knife node show NODE (options)

OSC Commands

  • knife osc_user create USER (options)
  • knife osc_user delete USER (options)
  • knife osc_user edit USER (options)
  • knife osc_user list (options)
  • knife osc_user reregister USER (options)
  • knife osc_user show USER (options)

Path-Based Commands

  • knife delete [PATTERN1 … PATTERNn]
  • knife deps PATTERN1 [PATTERNn]
  • knife diff PATTERNS
  • knife download PATTERNS
  • knife edit [PATTERN1 … PATTERNn]
  • knife list [-dfR1p] [PATTERN1 … PATTERNn]
  • knife show [PATTERN1 … PATTERNn]
  • knife upload PATTERNS
  • knife xargs [COMMAND]

Raw Commands

  • knife raw REQUEST_PATH

Recipe Commands

  • knife recipe list [PATTERN]

Role Commands

  • knife role bulk delete REGEX (options)
  • knife role create ROLE (options)
  • knife role delete ROLE (options)
  • knife role edit ROLE (options)
  • knife role env_run_list add [ROLE] [ENVIRONMENT] [ENTRY[,ENTRY]] (options)
  • knife role env_run_list clear [ROLE] [ENVIRONMENT]
  • knife role env_run_list remove [ROLE] [ENVIRONMENT] [ENTRIES]
  • knife role env_run_list replace [ROLE] [ENVIRONMENT] [OLD_ENTRY] [NEW_ENTRY]
  • knife role env_run_list set [ROLE] [ENVIRONMENT] [ENTRIES]
  • knife role from file FILE [FILE..] (options)
  • knife role list (options)
  • knife role run_list add [ROLE] [ENTRY[,ENTRY]] (options)
  • knife role run_list clear [ROLE]
  • knife role run_list remove [ROLE] [ENTRY]
  • knife role run_list replace [ROLE] [OLD_ENTRY] [NEW_ENTRY]
  • knife role run_list set [ROLE] [ENTRIES]
  • knife role show ROLE (options)

Serve Commands

  • knife serve (options)

SSH Commands

  • knife ssh QUERY COMMAND (options)

SSL Commands

  • knife ssl check [URL] (options)
  • knife ssl fetch [URL] (options)

Status Commands

  • knife status QUERY (options)

Tag Commands

  • knife tag create NODE TAG …
  • knife tag delete NODE TAG …
  • knife tag list NODE

User Commands

  • knife user create USERNAME DISPLAY_NAME FIRST_NAME LAST_NAME EMAIL PASSWORD (options)
  • knife user delete USER (options)
  • knife user edit USER (options)
  • knife user key create USER (options)
  • knife user key delete USER KEYNAME (options)
  • knife user key edit USER KEYNAME (options)
  • knife user key list USER (options)
  • knife user key show USER KEYNAME (options)
  • knife user list (options)
  • knife user reregister USER (options)
  • knife user show USER (options)

Knife Setup

In order to set up knife, one needs to move to .chef directory and create a knife.rb inside the chef repo, which tells knife about the configuration details. This will have a couple up details.

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                'node_name'
client_key               "#{current_dir}/USER.pem"
validation_client_name   'ORG_NAME-validator'
validation_key           "#{current_dir}/ORGANIZATION-validator.pem"
chef_server_url          'https://api.chef.io/organizations/ORG_NAME'
cache_type               'BasicFile'
cache_options( :path =>  "#{ENV['HOME']}/.chef/checksums" )
cookbook_path            ["#{current_dir}/../cookbooks"]

In the above code, we are using the hosted Chef server which uses the following two keys.

validation_client_name   'ORG_NAME-validator'
validation_key           "#{current_dir}/ORGANIZATION-validator.pem"

Here, knife.rb tells knife which organization to use and where to find the private key. It tells knife where to find the users’ private key.

client_key               "#{current_dir}/USER.pem"

The following line of code tells knife we are using the hosted server.

chef_server_url        'https://api.chef.io/organizations/ORG_NAME'

Using the knife.rb file, the validator knife can now connect to your organization’s hosted Opscode.

So, this brings us to the end of blog. This Tecklearn ‘Setup Knife in Chef’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Chef and build a career in DevOps domain, then check out our interactive, Continuous Delivery using Chef Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/continuous-delivery-using-chef/

Continuous Delivery using Chef Training

About the Course

Tecklearn has specially designed this Continuous Delivery using Chef Training Course to advance your skills for a successful career in this domain. The course will cover different components of Chef and how they are used in software development operations. The course consists of important concepts like Continuous Delivery (CD) using Chef, Chef Framework, How Chef Works, Chef Advantages and Chef Installation. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Chef.

Why Should you take Continuous Delivery using Chef Training?

  • The average salary for a Senior Development Operations (DevOps) Engineer with Chef skills is $118, 435. – PayScale.com
  • Airbnb, Facebook, Slack, Shopify, Digital Ocean & many other MNC’s worldwide use Chef across industries.
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Continuous Delivery using Chef

  • Continuous Delivery
  • What is Chef
  • Chef Framework
  • How Chef Works
  • Chef Advantages
  • Chef Installation
  • Hands on

Got a question for us? Please mention it in the comments section and we will get back to you.

 

0 responses on "Setup Knife in Chef"

Leave a Message

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