Chef - Nodes


Advertisements

Knife preflight shows details about all the nodes which uses a certain cookbook before uploading it to Chef server.

Getting Started

In order to get started, we need to have knife-preflight gem installed.

Step 1 − Define the path in the gem file.

vipin@laptop:~/chef-repo $ subl Gemfile 
source 'https://rubygems.org' 
gem '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

Run knife-preflight on the given cookbook.

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.

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.

Advertisements