Chef - 节点

Knife preflight 在将某个Cookbook(食谱)上传到 Chef 服务器之前,显示所有使用该Cookbook(食谱)的节点的详细信息。

入门

为了开始,我们需要安装 knife-preflight gem。

步骤 1 − 在 gem 文件中定义路径。

vipin@laptop:~/chef-repo $ subl Gemfile
source 'https://rubygems.org'
gem 'knife-preflight'

步骤 2 −运行 bundler 安装 knife-preflight gem。

vipin@laptop:~/chef-repo $ bundle install 
Fetching gem metadata from https://rubygems.org/ 
...TRUNCATED OUTPUT... 
Installing knife-preflight (0.1.6)

工作方法

在给定的 cookbook 上运行 knife-preflight。

我们可以运行 preflight 命令来找出哪些节点和角色在其扩展的运行列表中具有给定的 cookbook。

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 

有多种方法可以在节点上执行Cookbook(食谱)。

  • 您可以通过将Cookbook(食谱)添加到节点的运行列表中,将Cookbook(食谱)直接分配给节点。

  • 您可以将Cookbook(食谱)添加到角色,并将角色添加到节点的运行列表中。

  • 您可以将角色添加到另一个角色的运行列表中,并将该角色添加到节点的运行列表中。

  • Cookbook(食谱)可以是另一个使用的Cookbook(食谱)的依赖项。

无论Cookbook(食谱)最终如何出现在节点的运行列表中,knife preflight 命令都会捕获它,因为 Chef 将所有扩展的角色和Cookbook(食谱)列表存储在节点属性中。knife preflight 命令会针对这些节点属性发出搜索。