1
votes

I have a cookbook that needs to install software for both Windows and RHEL boxes. There is an existing cookbook I can leverage for the RHEL boxes, which I'll call linux-foo. I include it in the default recipe with include_recipe 'linux-foo' and add with depends 'linux-foo' in the cookbook metadata.

However, by adding the dependency to metadata it's breaking my custom Windows recipe. I'm getting

   NoMethodError
   -------------
   undefined method `[]' for nil:NilClass

   Platform:
   ---------
   x64-mingw32

when attempting to converge the windows recipe in test-kitchen. It's referring to the .../linux-foo/attributes/default.rb as the culprit, but doesn't specify which attribute.

Is there a way to still include_recipe 'linux-foo' but not include it as a hard dependency in metadata.rb OR wrap the 3rd party cookbook's default attributes somehow?

It looks like I either keep the dependency and break the windows recipe or separate the linux and windows recipes into separate cookbooks.

1

1 Answers

0
votes

Unfortunately there is no direct way to do this. Chef does not support optional dependencies at this time.

The best fix is to make your linux-foo cookbook safe to load on non-Linux machines, even if the recipes aren't. If you look in the file mentioned in the error report you can find the full stack trace, that will tell you which line needs fixing (though there may be more than one).