DELUXEnized
DELUXEnized

Reputation: 1278

Get deployed cookbook version

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?

Upvotes: 11

Views: 3697

Answers (1)

jtimberman
jtimberman

Reputation: 8258

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.

Upvotes: 15

Related Questions