Which cookbook version used in chef-client run?


#1

Hi,

Is there a way to list or to log which cookbook version was used during a
chef-client run. I know I can crack open metadata.rb files in the chef/cache
directory but that is a bit clunky. It is also usefull information to log I
would say.

Cheers,

Flo


#2

If nothing, you can look in /var/chef/cache/cookbooks/ to see what was actually published from the upstream chef server. This is also useful when someone is updating the cookbooks, without actually changing the version number of the cookbook. (I’ve run into this lately with manual updates to an environment before code could get through a review process, particularly for testing chef cookbooks.)


From: Florian Hehlen [florian.hehlen@gmail.com]
Sent: Thursday, October 10, 2013 6:03 AM
To: chef@lists.opscode.com
Subject: [chef] which cookbook version used in chef-client run?

Hi,

Is there a way to list or to log which cookbook version was used during a chef-client run. I know I can crack open metadata.rb files in the chef/cache directory but that is a bit clunky. It is also usefull information to log I would say.

Cheers,
Flo


#3

It’s a little dirty, but if you crack open the run context you can do it:

—8<— cut here —8<—

log "—Writing all ckbks and versions—"
cookbooks = @run_context.cookbook_collection

log "The recipes were these: #{cookbooks.keys.map {|x|
cookbooks[x].name + " " + cookbooks[x].version} }"
log "—End Writing all ckbks and versions—

—8<— cut here —8<—

Credit goes to Sean Horn for this tidbit of code.

  • Julian

On Thu, Oct 10, 2013 at 6:03 AM, Florian Hehlen
florian.hehlen@gmail.com wrote:

Hi,

Is there a way to list or to log which cookbook version was used during a
chef-client run. I know I can crack open metadata.rb files in the chef/cache
directory but that is a bit clunky. It is also usefull information to log I
would say.

Cheers,

Flo


[ Julian C. Dunn jdunn@aquezada.com * Sorry, I’m ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]


#4

It would be really good to have this logged by default. I got into a problem where as far as I can see chef chose to one version over an other of recipe and it took me a while to figure out that this was happening. Having the versions logged would have helped identify the problem.

Here is what happened. Imagine three cookbooks A,B, C. B and C depend on A. But they don’t necessarily depend on the same version of A because B and C just do different things. Now imagine B depends explicitly on version 1 of A and C depends explicitly on version 2 of A. Finally lets say I add B and C to the run list of a node.

The question is: Which version of A will be used? What I saw was that version 1 was being used for both. Has anyone else experienced this? Is this expected behavior. It does not seem to respect the cookbook’ depends’ contract.

Cheers,
Florian

-----Original Message-----
From: Julian C. Dunn [mailto:jdunn@aquezada.com]
Sent: 10 October 2013 14:44
To: chef@lists.opscode.com
Subject: [chef] Re: which cookbook version used in chef-client run?

It’s a little dirty, but if you crack open the run context you can do it:

—8<— cut here —8<—

log "—Writing all ckbks and versions—"
cookbooks = @run_context.cookbook_collection

log "The recipes were these: #{cookbooks.keys.map {|x| cookbooks[x].name + " " + cookbooks[x].version} }"
log "—End Writing all ckbks and versions—

—8<— cut here —8<—

Credit goes to Sean Horn for this tidbit of code.

  • Julian

On Thu, Oct 10, 2013 at 6:03 AM, Florian Hehlen florian.hehlen@gmail.com wrote:

Hi,

Is there a way to list or to log which cookbook version was used
during a chef-client run. I know I can crack open metadata.rb files in
the chef/cache directory but that is a bit clunky. It is also usefull
information to log I would say.

Cheers,

Flo


[ Julian C. Dunn jdunn@aquezada.com * Sorry, I’m ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

LEGAL DISCLAIMER
This communication and any attached documents are strictly confidential and/or legally privileged and they may not be used or disclosed by someone who is not a named recipient. If you have received this electronic communication in error please notify the sender by replying to this electronic communication inserting the word “misdirected” as the subject and delete this communication from your system.


#5

On Thursday, October 10, 2013 at 6:24 AM, Florian Hehlen wrote:

It would be really good to have this logged by default. I got into a problem where as far as I can see chef chose to one version over an other of recipe and it took me a while to figure out that this was happening. Having the versions logged would have helped identify the problem.

Here is what happened. Imagine three cookbooks A,B, C. B and C depend on A. But they don’t necessarily depend on the same version of A because B and C just do different things. Now imagine B depends explicitly on version 1 of A and C depends explicitly on version 2 of A. Finally lets say I add B and C to the run list of a node.

The question is: Which version of A will be used? What I saw was that version 1 was being used for both. Has anyone else experienced this? Is this expected behavior. It does not seem to respect the cookbook’ depends’ contract.

Cheers,
Florian

What frequently causes this is an older version of B or C do not have an explicit dependency on A, or do not constrain which version of A they want. So the solution of the dependency graph uses the older version so that all the constraints can be satisfied.


Daniel DeLeo