Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get deployed cookbook version

Tags:

chef-infra

Where can I find the deployed cookbook version? It seems that the automatic attributes do not listen the versions.

Is there a way to access the cookbook_version somewhere in a recipe or template?

like image 261
DELUXEnized Avatar asked Dec 03 '12 18:12

DELUXEnized


People also ask

How do I find my cookbook version?

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.

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.

How do you verify a Chef cookbook?

Step 1 − Install the cookbook using the following command. Step 2 − Run the knife cookbook test commands on the working cookbook. Step 3 − Break something in the cookbook and test again. Step 4 − Run the knife test command again.


1 Answers

You have to access the cookbook collection that the Chef run knows about.

run_context.cookbook_collection[cookbook_name].metadata.version

The run context is an object that tracks the context of the Chef run.

The cookbook_collection method returns a hash-like object of all the cookbooks that Chef has in the local cache.

The cookbook_name method returns the name of "this" cookbook, so it looks up the cookbook in the collection. The collection has all the metadata in the cookbooks, which can be selected via accessors. In this case since you want "version", use the "version" accessor.

like image 148
jtimberman Avatar answered Oct 04 '22 19:10

jtimberman