Platform specific config in a cookbook's metadata.rb?


#1

Taking the erlang cookbook as an example:

depends “apt”, ">= 1.7.0"
depends “yum”, ">= 0.5.0"
depends “build-essential”

We’re a CentOS-only shop so it seems silly to have to load the apt cookbook (and maintain the version forced march) when it will never be used.

I was thinking something like:

case
when platform_family?(“debian”)
depends “apt”, ">= 1.7.0"
suggests "build-essential"
when platform_family?(“rhel”)
depends “yum”, ">= 0.5.0"
suggests "build-essential"
else
depends "build-essential"
end

This does not work. I suppose these could be “suggest” and let the include_recipe fail. Is there an “official” pattern for this?

Thanks.

Joe

#2

Joe,

The metadata.rb file is actually a very thin wrapper around being a
metadata.json file. You should only have static data in it because by the
time knife uploads it to the chef-server, knife will be uploading the json
version. The chef-server does not run any code at all from your cookbooks.

The typical patterns are: 1) to depend on all the platform-specific
cookbooks; 2) to document all the platform-specific cookbooks for the
sysadmin using chef and require the sysadmin to set up the
run-lists/roles/top-level-cookbooks correctly, but not to depend on them;
3) to enhance Chef to understand platform-specific cookbooks.

Cheers,
Jay Feldblum


#3

I believe what you’re looking for is addressed here:
https://tickets.opscode.com/browse/CHEF-3871


~~ StormeRider ~~

“Every world needs its heroes […] They inspire us to be better than we
are. And they protect from the darkness that’s just around the corner.”

(from Smallville Season 6x1: “Zod”)

On why I hate the phrase “that’s so lame”… http://bit.ly/Ps3uSS

On Mon, Oct 14, 2013 at 2:26 PM, joe.nuspl nuspl@nvwls.com wrote:

Taking the erlang cookbook as an example:

depends “apt”, ">= 1.7.0"
depends “yum”, ">= 0.5.0"
depends “build-essential”

We’re a CentOS-only shop so it seems silly to have to load the apt
cookbook (and maintain the version forced march) when it will never be used.

I was thinking something like:

case
when platform_family?(“debian”)
depends “apt”, ">= 1.7.0"
suggests "build-essential"
when platform_family?(“rhel”)
depends “yum”, ">= 0.5.0"
suggests "build-essential"
else
depends "build-essential"
end

This does not work. I suppose these could be “suggest” and let the
include_recipe fail. Is there an “official” pattern for this?

Thanks.

    Joe