Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract cookbook name and version during chef-client run

Please help me with the recipe to pull the cookbook name and version during the chef-client run. I want to store the values to variables and use as part of my recipe.

I am finding difficulty on how to pull the cookbook version and name from the recipe during chef-client run on the node.

Thanks in advance.

like image 881
thecontent Avatar asked Apr 03 '14 09:04

thecontent


People also ask

How do I clear the list of cookbooks in Chef-client?

Replace the current run-list with the specified items. This option will clear the list of cookbooks (and related files) that is cached on the node. (Starting in chef-client 12.0, this option will not clear the list of cookbooks.) Run the chef-client only once and cancel interval and splay options.

How to check the last Chef-client run failure issues?

In order to check the last Chef-Client run especially failure issues when we are developing a new cookbook, we need to know what exactly went wrong. Even though Chef prints everything in stdout, one might want to see the debug log again. If we want to test, we need to have a broken cookbook which is failing on compilation.

How do I create a Chef-client run-list?

The first chef-client run, by default, contains an empty run-list. A run-list can be specified as part of the initial bootstrap operation using the --run-list option as part of the knife bootstrap subcommand.

How does the Chef-client register with the Chef server?

During the initial chef-client run, the chef-client will register with the Chef server using the private key assigned to the chef-validator, after which the chef-client will obtain a client.pem private key for all future authentication requests to the Chef server.


1 Answers

You can access the current cookbook's name through the cookbook_name variable.

The version of this cookbook (and other cookbooks) can be retrieved through the run_context:

run_context.cookbook_collection[cookbook_name].version
like image 168
StephenKing Avatar answered Sep 28 '22 00:09

StephenKing