Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query cookbook versions on a node?

Usage case: The DevOps team launched a node sometime ago, and my team would like to know what's the version(s) of one/several cookbook(s) being used in the run_list. Our DevOps team is firefighting so we'd like to find a way to be self-sufficient.

Commands Tried: knife cookbook show COOKBOOK give all possible versions, but does not specify which one being used.

knife node show NODE shows all cookbooks, but there's no version info attached.

Question: Is there a command (something similar to knife search, ohai) to query the chef-server for the versions deployed on the node?

like image 277
digit plumber Avatar asked Jun 22 '15 18:06

digit plumber


People also ask

How do I update my cookbook?

On the stack's page, click Run Command and select the Update Custom Cookbooks command. Add a comment if desired. Optionally, specify a custom JSON object for the command to add custom attributes to the stack configuration and deployment attributes that AWS OpsWorks Stacks installs on the instances.

What is Berksfile?

Berksfile is the most crucial component of Berkshelf! It's just like metadata for Chef. However, the usage is somewhat different. Berksfile makes it simple to download a dependency cookbook from chef supermarket (or other places) and upload to the cookbook repository on the server.


3 Answers

If you can ssh into the box you can look under /var/chef/cache/cookbooks/<cookbook name>/metadata.json to find the version.

Also, you can access it during a chef run by looking at @run_context.cookbook_collection, but that probably doesn't help.

Generally the cookbook version is defined by the environment, but since environments change over time, you can't really trust that to be the same set that was used when this node last converged (especially if it's been a while).

By far your safest option will be to look at the chef cache.

like image 50
Tejay Cardon Avatar answered Oct 13 '22 01:10

Tejay Cardon


If you're using ohai (you probably are), you can do something like this:

knife search -i 'cookbooks:your-cookbook' -a cookbooks.your-cookbook.version

This will give you output that shows the hostname and the cookbook version:

1 items found

server.name.example:
  cookbooks.cs-redis.version: 0.3.2
like image 45
oskarpearson Avatar answered Oct 13 '22 00:10

oskarpearson


In our organisation we use a base cookbook to set an attribute on the node with the cookbook versions.

run_context.cookbook_collection.each do |key, cookbook|
  node.set['base_cookbook']['cookbook_versions'][cookbook.name] = cookbook.version
end

Then we can query the versions used by a node with

knife node show <node-name> -a base_cookbook.cookbook_versions
like image 28
Matt Cole Avatar answered Oct 13 '22 00:10

Matt Cole