Chef client execution of multiple recipes

Hello Chef Gurus,
I am a newbie to chef automation and stuck with an issue. I have a cookbook two recipes with one recipe creating a folder and store a file into it and the second recipe reads from this file. I have added the recipes in a run list in the order.

When I execute the run_list, chef-client throws the error with second recipe saying that the file does not exist, which is supposed to be created by the first recipe.

Is there a way to avoid this error, as the file has to be created on bootstrap and should be created before the cookbook execution

Thanks
Babu G

I assume you’re being hit by the two-pass problem in your recipe code.

See https://docs.chef.io/chef_client.html#the-chef-client-run and https://coderanger.net/two-pass/ for insight about it.

Thanks Tensi for your valuable comment. I modified my script as per the document suggested but still same error is happening. Following is the modified ruby block .

file ‘/u01/app/paas/keys/ssh_public.pub’ do
vmPublicKeyText = File.read("/u01/app/paas/keys/ssh_public.pub")
only_if { File.exist?(’/u01/app/paas/keys/ssh_public.pub’) }
puts vmPublicKeyText
end

As I said earlier, the “ssh_public.pub” file is created by a recipe before the current recipe.
Please check my ruby block and correct me if anything went wrong,

Issue resolved after creating a ruby_block on top of my actual code. Thanks a lot again for your help