metadatachef-infracookbook

Dynamic metadata according platform?


Is it possible to detect the platform within the metadata.rb file of a Cookbook?

For example, something like this:

if node['platform'] == 'aix'
   depends "cats", "< 1.0"
end

if node['platform'] == 'ubuntu'
   depends "cats", "> 1.0"
end

But that is not possible since node is not available in that context. Is there any other way?


Solution

  • No, cookbook dependencies are entirely static. This has been discussed for some point in the future but no major proposals have emerged. If you are interested in contributing I would invite you to submit a Chef RFC with a proposed fix if you can come up with one :)

    The sticky point is usually that there are reasons for conditional dependencies beyond simply per-platform logic. This comes up often for things like runit vs. systemd, mysql vs. postgres, and apache vs. nginx.