Chef Recipe: File not found issue (does not contain a file at any of these locations)

1k views Asked by At

I'm trying to bootstrap a machine with a recipe that contains a call to cookbook_ file resource with action:create. The following issue occurs during execution (some information has been redacted):

FATAL: Chef::Exceptions::FileNotFound: cookbook_file[/path/to/file]
(XXXX::default line 25) had an error: Chef::Exceptions::FileNotFound:
Cookbook 'XXXX' (0.1.0) does not contain a file at any of these
locations:   files/default/file   files/second_folder/file

I checked my /chef/cookbooks/cookbook_name/recipe/files/default and /second_folder directories, and the files required are there, but Chef is just refusing to recognize them. I'm not sure what could be causing this issue. Any help is much appreciated.

2

There are 2 answers

0
xleon90 On

Default folder solution

Your source file file should be placed on your cookbook at:

cookbook_name/files/default/file

Then you should use the cookbook_file as follow:

cookbook_file "/home/user/file") do
   source 'file'
   owner 'root'
   group 'root'
   mode '0644'
   action :create
end

Custom folder solution

You can also place your file on a different folder from default one as your second_folder for example:

cookbook_name/files/second_folder/file

This way you should specify on source also the not default directory as follow:

cookbook_file "/home/user/file") do
   source 'second_folder/file'
   owner 'root'
   group 'root'
   mode '0644'
   action :create
end
0
Bikramjit Singh On

Check ignore files you might have inherited from cookbook template. In my case the error was to not able finding an xml file and I had *.xml in both ignore files chefignore and .gitignore