Order of execution

If a recipe is -

1)cookbook_file block

2)include_recipe block

which will converge first, include or cookbook_file

i want cookbook_file to converge before include runs? how can i do this

Cookbook_file should/would execute first. I actually have recipes that have those 2 steps just like that and it works as intended.

but in my case, it is first executing include_recipe…
and the recipe which is being included is using some ruby code.

my included recipe has this content which is executing first:-1:

my_secret_key = Chef::EncryptedDataBagItem.load_secret("#{secretke}")

but this key is getting created on node via cookbook_file resource which in this case is running afterwards so key is not being created at first and gives error

Take a look at the notifies property.

Using something like that is the only way I’ve found to ensure a resource
is converged in a specific order.

You’ve confused compile with converge. The code below is not a resource, and would be evaluated in the compile phase. Perhaps look in to using run_action to force your cookbook_file to converge during compile.

–Jp Robinson

can you share the sample code…how should i write that in cookbook_file resource so that the cookbook_file would be evaluated in compile

I wan that cookbook_file resource shoudl run before this code

my_secret_key = Chef::EncryptedDataBagItem.load_secret("#{secretke}")

but now i cannot apply notifies in this code as it is not a resource.

Should i apply notifies in cookbook_file itself to run it in complie phase.

Nopes…notifies in cookbook_file itself is not going to work. Please suggest some idea

The run_action syntax is documented as part of the common functionality for all resources at https://docs.chef.io/resource_common.html

Please read the documentation carefully, it will help greatly.

–Jp Robinson