Chef 简明教程
Chef - Knife Setup
Knife 是 Chef 的命令行工具,用于与 Chef 服务器进行交互。人们使用它来上传 cookbook 并管理 Chef 的其他方面。它在本地计算机上的 chefDK(Repo)与 Chef 服务器之间提供一个界面。它有助于管理:
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 提供了一组用于管理 Chef 基础设施的命令。
Knife provides a set of commands to manage Chef infrastructure.
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)
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)
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]
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)
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
为了设置 Knife,需要移动到 .chef 目录并在 Chef 仓库中创建 knife.rb ,它会告知 Knife 有关配置详情。这里会有几个详细信息。
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"]
在上面的代码中,我们使用的是托管 Chef 服务器,它采用以下两个密钥。
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"
此处,knife.rb 告知 Knife 要使用哪个组织以及在哪儿查找私钥。它告知 Knife 在哪儿查找用户的私钥。
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"
以下代码行告知 Knife 我们使用的是托管服务器。
The following line of code tells knife we are using the hosted server.
chef_server_url 'https://api.chef.io/organizations/ORG_NAME'
使用 knife.rb 文件,validator knife 现在可以连接到您组织的托管 Opscode。
Using the knife.rb file, the validator knife can now connect to your organization’s hosted Opscode.