[chef] Re: platform agnostic roles and/or cookbooks


Chronological Thread 
  • From: Jay Feldblum < >
  • To:
  • Subject: [chef] Re: platform agnostic roles and/or cookbooks
  • Date: Sat, 12 May 2012 19:17:46 -0400

Cooper,

You could write your own recipe in your own custom "my-base" cookbook.

In your "my-base" cookbook's default recipe, you can write:

if platform?("ubuntu")
  include_recipe "apt"
end

In your "my-base" cookbook's metadata, be sure to write:

depends "apt"

That last line in the metadata doesn't actually add "recipe[apt]" to the run-list. It just makes sure that the apt cookbook gets downloaded to the chef-client, so that it can be run by your recipe, if you want to run it.

Then you can remove "recipe[apt]" from your base role's run-list. Instead, you can add "recipe[my-base]", which includes the apt recipe only on ubuntu.

Cheers,
Jay

On Sat, May 12, 2012 at 5:31 PM, Cooper Simmons < " target="_blank"> > wrote:
Hello all.

I would like to bootstrap a server with a base role and not care if it's rhel/centos or ubuntu/debian.
I'm experimenting and using a base role to run the cookbooks users, sudo, & ntpd.
But ubuntu also needs the apt cookbook to run 'apt-get update' first. My bootstrap for rhel/centos is failing because it can't run the apt cookbook.

Is there something in the yum & apt cookbooks (or any cookbook for that matter) that essentially says "only run this if you're platform X, else skip this cookbook"?

I'm fairly new and it seems like there should be a simple way to solve this.
Thanks!





Archive powered by MHonArc 2.6.16.

§