I'm writing a chef cookbook recipe which aims to place a file onto a node server.
cookbook_file "/path/to/node/dir/file_name" do
source "file_name"
owner "ec2-user"
group "ec2-user"
end
I intend to allow a user of this cookbook to place the source file in his/her knife solo repository's "site-cookbooks" directory.
The problem is this configuration throws Chef::Exceptions::FileNotFound: Cookbook 'my-cookbook' (0.1.0) does not contain a file at any of these locations: ...
upon knife solo cook
deployment.
I tried specifying different cookbook_path
options in the knife solo repository's .chef/knife.rb
file but was unsuccessful.
What is the right way to achieve this? Or does chef not work like this and if so, what is the preferred alternative methodology? Is this a sign I should consolidate the cookbook and the knife solo repository into a single knife solo repository?
cookbooks
vs. site-cookbooks
(and all other variants of cookbooks_path
) are just about where to load cookbooks from. The source
resource attribute only looks for things inside a cookbook, not in one of those paths directly. You don't have an explicit cookbook in your resource declaration, so it is going to look in the cookbook that the recipe that code is in. Because it is a cookbook_file
, it has to be in the files/
subfolder inside the cookbook.
There is no way to tell Chef or knife-solo to send and use a random loose file like I think you are suggesting, it is all based around cookbooks and other Chef data types. You could use a remote_file
resource and allow the recipe to pull from a user-specified HTTPS server.