Chef 简明教程
Chef - Nodes
Knife preflight 展示了使用某个配方的手册的所有节点的详细信息,然后将其上传到 Chef 服务器。
Knife preflight shows details about all the nodes which uses a certain cookbook before uploading it to Chef server.
Getting Started
为了开始,我们需要安装 knife-preflight 宝石。
In order to get started, we need to have knife-preflight gem installed.
Step 1 - 定义宝石文件中的路径。
Step 1 − Define the path in the gem file.
vipin@laptop:~/chef-repo $ subl Gemfile
source 'https://rubygems.org'
gem 'knife-preflight'
Step 2 - 运行 bundler 来安装 knife-preflight 宝石。
Step 2 − Run bundler to install knife-preflight gem.
vipin@laptop:~/chef-repo $ bundle install
Fetching gem metadata from https://rubygems.org/
...TRUNCATED OUTPUT...
Installing knife-preflight (0.1.6)
Working Method
对给定的配方运行 knife-preflight。
Run knife-preflight on the given cookbook.
我们可以运行 preflight 命令来找出在它们扩展的运行列表中具有给定配方的那些节点和角色。
We can run the preflight command to find out which nodes and roles have the given cookbook in their expanded run lists.
vipin@laptop:~/chef-repo $ knife preflight ntp
Searching for nodes containing ntp OR ntp::default in their
expanded run_list...
2 Nodes found
www-staging.example.com
cms-staging.example.com
Searching for roles containing ntp OR ntp::default in their
expanded run_list...
3 Roles found
your_cms_role
your_www_role
your_app_role
Found 6 nodes and 3 roles using the specified search
criteria
有许多方法能让配方在节点上执行。
There are multiple ways for a cookbook to get executed on the node.
-
You can assign the cookbook directly to a node by adding it to the node’s run list.
-
You can add a cookbook to the role and add the role to the node’s run list.
-
You can add the role to the run list of another role and add that other role to the node’s run list.
-
A cookbook can be a dependency of another used cookbook.
无论配方如何最终进入节点的运行列表,knife preflight 命令将会捕获它,因为 Chef 将所有扩展的角色列表和食谱存储在节点属性中。knife preflight 命令会准确地搜索这些节点属性。
No matter how a cookbook ends up in a node’s run list, the knife preflight command will catch it as Chef stores all expanded lists of roles and recipes in node attributes. The knife preflight command issues a search for exactly those node attributes.