0

My chef run recently throws this error:

Chef Client failed. 22 resources updated in 90.306407696 seconds
[2014-12-19T19:47:24+00:00] ERROR: cookbook_file[/srv/mycookbook/static/a.png] (mycookbook::_deploy line 82) had an error: Chef::Exceptions::FileNotFound: Cookbook 'mycookbook' (0.4.5) does not contain a file at any of these locations:
  files/ubuntu-12.04/static/a.png
  files/ubuntu/static/a.png
  files/default/static/a.png

This cookbook _does_ contain: ['a.css','b.html','c.html']

That's because the main cookbook mycookbook (which I don't own) has these lines:

node['myattributes']['theme']['static_files'].each do |file|
  cookbook_file node['myattributes']['install_dir'] + "/static/" + file do
    source "static/#{file}"
    owner node['myattributes']['user']
    group node['myattributes']['group']
    cookbook node['myattributes']['theme']['source_cookbook']
  end
end

but my child or wrapper cookbook which uses mycookbook has these lines with different attributes and failed:

override['myattributes']['theme']['compile_files'] = ['a.html']
override['myattributes']['theme']['static_files'] = ['a.png']

And I have these files store under my wrapper cookbook files/default/static/ and files/default/etc/

I already know what the problem is. My wrapper cookbook don't have some files expected by mycookbook, but why would I ? These attributes should be overriden anyway.

My question is there a better way to handle the files checked under files/default that the recipe definitions are defined in the parent cookbook, and the wrapper cookbook just define different set of attributes with different files?

samxiao
  • 2,587
  • 5
  • 38
  • 59

1 Answers1

1

You need to set node['myattributes']['theme']['source_cookbook'] to `then name of your wrapper cookbook so it looks in the correct cookbook.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Thanks! That seems to work! May I ask if it's a good idea to use `cookbook_file` resource or not? Because I'm not sure why the original author did it this way, but I thought this would be much better accomplished when building a library helper. – samxiao Dec 20 '14 at 01:24
  • 1
    Not sure what else you would use, cookbook_file is the only way to copy files from a cookbook to the filesystem. As for making a recipe vs. an extensible resource to better cope with this kind of thing, I think I can confidently say I'm in the latter camp since I invented a lot of it. – coderanger Dec 20 '14 at 01:34
  • It was the easiest way for me (in the [gerrit cookbook](https://github.com/TYPO3-cookbooks/gerrit/blob/refactoring/recipes/_deploy.rb#L67-88) to let wrapper cookbook supply files for the Gerrit theme. I see the point, where a `gerrit_theme_file` LWRP would make things a bit easier. (But I'm in general unhappy with the state of the cookbook given a lack of time). But finally, the files have to be deployed either through `remote_file` or `cookbook_file` (as the `template` resource to what you're probably more used to does not work well for binaries (images). – StephenKing Dec 20 '14 at 07:58