English 中文(简体)
Chef - Knife Setup
  • 时间:2024-09-17

Chef - Knife Setup


Previous Page Next Page  

Knife is Chef’s command-pne 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 cpent on Chef nodes

Knife provides a set of commands to manage Chef infrastructure.

Bootstrap Commands

    knife bootstrap [SSH_USER@]FQDN (options)

Cpent Commands

    knife cpent bulk delete REGEX (options)

    knife cpent create CLIENTNAME (options)

    knife cpent delete CLIENT (options)

    knife cpent edit CLIENT (options)

    Usage: C:/opscode/chef/bin/knife (options)

    knife cpent key delete CLIENT KEYNAME (options)

    knife cpent key edit CLIENT KEYNAME (options)

    knife cpent key pst CLIENT (options)

    knife cpent key show CLIENT KEYNAME (options)

    knife cpent pst (options)

    knife cpent reregister CLIENT (options)

    knife cpent show CLIENT (options)

Configure Commands

    knife configure (options)

    knife configure cpent 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 pst (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 pst (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 pst (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 pst (options)

    knife environment show ENVIRONMENT (options)

Exec Commands

    knife exec [SCRIPT] (options)

Help Commands

    knife help [pst|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 pst (options)

    knife node run_pst add [NODE] [ENTRY[,ENTRY]] (options)

    knife node run_pst remove [NODE] [ENTRY[,ENTRY]] (options)

    knife node run_pst 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 pst (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 pst [-dfR1p] [PATTERN1 ... PATTERNn]

    knife show [PATTERN1 ... PATTERNn]

    knife upload PATTERNS

    knife xargs [COMMAND]

Raw Commands

    knife raw REQUEST_PATH

Recipe Commands

    knife recipe pst [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_pst add [ROLE] [ENVIRONMENT] [ENTRY[,ENTRY]] (options)

    knife role env_run_pst clear [ROLE] [ENVIRONMENT]

    knife role env_run_pst remove [ROLE] [ENVIRONMENT] [ENTRIES]

    knife role env_run_pst replace [ROLE] [ENVIRONMENT] [OLD_ENTRY] [NEW_ENTRY]

    knife role env_run_pst set [ROLE] [ENVIRONMENT] [ENTRIES]

    knife role from file FILE [FILE..] (options)

    knife role pst (options)

    knife role run_pst add [ROLE] [ENTRY[,ENTRY]] (options)

    knife role run_pst clear [ROLE]

    knife role run_pst remove [ROLE] [ENTRY]

    knife role run_pst replace [ROLE] [OLD_ENTRY] [NEW_ENTRY]

    knife role run_pst 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 pst 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 pst USER (options)

    knife user key show USER KEYNAME (options)

    knife user pst (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  
cpent_key               "#{current_dir}/USER.pem" 
vapdation_cpent_name    ORG_NAME-vapdator  
vapdation_key           "#{current_dir}/ORGANIZATION-vapdator.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.

vapdation_cpent_name    ORG_NAME-vapdator  
vapdation_key           "#{current_dir}/ORGANIZATION-vapdator.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.

cpent_key               "#{current_dir}/USER.pem" 

The following pne 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 vapdator knife can now connect to your organization’s hosted Opscode.

Advertisements