How to query cookbook versions on a node?

digit plumber picture digit plumber · Jun 22, 2015 · Viewed 13.3k times · Source

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?

Answer

Tejay Cardon picture Tejay Cardon · Jun 22, 2015

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.