How to obtain cookbook dependencies from metadata.rb?

Ohai Chefs,

what’s the easiest way to obtain the cookbook dependencies defined in
metadata.rb (only direct dependencies are required)?

I’m not too firm with the chef internals yet, thus my first idea was to
evaluate metadata.rb and recording the depends calls via method_missing

  • but this doesn’t feels quite right…

Thanks!
Torben

Background:

First, I want to emulate Berkshelfs 'metadata' keyword inside a librarian
Cheffile.

Then I want to override the location for some of the metadata-defined
cookbook dependencies in the Cheffile (e.g. use github branch rather than
community site)

Has someone done something like this already?

Am 09.01.2013 22:44 schrieb "Torben Knerr" ukio@gmx.de:

Ohai Chefs,

what's the easiest way to obtain the cookbook dependencies defined in
metadata.rb (only direct dependencies are required)?

I'm not too firm with the chef internals yet, thus my first idea was to
evaluate metadata.rb and recording the depends calls via method_missing

  • but this doesn't feels quite right...

Thanks!
Torben

Has someone done something like this already?
Um, berkshelf. :slight_smile:

You can probably figure out some of the work from there. But I have no
idea if the Chef cookbook metadata parser will allow for anything
other than a version string following a cookbook name.

Ref: chef/chef/lib/chef/cookbook/metadata.rb at 10-stable · chef/chef · GitHub

-M

On Wed, Jan 9, 2013 at 5:26 PM, Torben Knerr ukio@gmx.de wrote:

Background:

First, I want to emulate Berkshelfs 'metadata' keyword inside a librarian
Cheffile.

Then I want to override the location for some of the metadata-defined
cookbook dependencies in the Cheffile (e.g. use github branch rather than
community site)

Has someone done something like this already?

Am 09.01.2013 22:44 schrieb "Torben Knerr" ukio@gmx.de:

Ohai Chefs,

what's the easiest way to obtain the cookbook dependencies defined in
metadata.rb (only direct dependencies are required)?

I'm not too firm with the chef internals yet, thus my first idea was to
evaluate metadata.rb and recording the depends calls via method_missing

  • but this doesn't feels quite right...

Thanks!
Torben

Hey Torben,

If you're familiar with Ruby you should be able to read the Berkshelf source to get an idea of how I implemented the metadata keyword. The Berkshelf code base is pretty friendly and you should feel free to use any of the classes which aren't marked @api private in your own codebase.

Is there a reason you aren't using Berkshelf for this? The use that you are describing is 100% supported and something that I use in my projects everyday. (overriding the locations of the dependencies found in the metadata)

--
Jamie Winsor
@resetexistence

On Wednesday, January 9, 2013 at 2:31 PM, Mike wrote:

Has someone done something like this already?

Um, berkshelf. :slight_smile:

You can probably figure out some of the work from there. But I have no
idea if the Chef cookbook metadata parser will allow for anything
other than a version string following a cookbook name.

Ref: chef/chef/lib/chef/cookbook/metadata.rb at 10-stable · chef/chef · GitHub

-M

On Wed, Jan 9, 2013 at 5:26 PM, Torben Knerr <ukio@gmx.de (mailto:ukio@gmx.de)> wrote:

Background:

First, I want to emulate Berkshelfs 'metadata' keyword inside a librarian
Cheffile.

Then I want to override the location for some of the metadata-defined
cookbook dependencies in the Cheffile (e.g. use github branch rather than
community site)

Has someone done something like this already?

Am 09.01.2013 22:44 schrieb "Torben Knerr" <ukio@gmx.de (mailto:ukio@gmx.de)>:

Ohai Chefs,

what's the easiest way to obtain the cookbook dependencies defined in
metadata.rb (only direct dependencies are required)?

I'm not too firm with the chef internals yet, thus my first idea was to
evaluate metadata.rb and recording the depends calls via method_missing

  • but this doesn't feels quite right...

Thanks!
Torben

Hey Mike, Jamie,

Thanks for the replies!

The knockout requirement for librarian in my specific case is http_proxy
support.

I would go for Berkshelf just because of 'metadata' otherwise.
Both are great tools, librarian with a focus on simplicity and Berkshelf
supporting more workflow-like stuff. I like both equally, but neither fully
supports my current case :wink:

Cheers, Torben

Am 09.01.2013 23:47 schrieb "Jamie Winsor" jamie@vialstudios.com:

Hey Torben,

If you're familiar with Ruby you should be able to read the Berkshelf
source to get an idea of how I implemented the metadata keyword. The
Berkshelf code base is pretty friendly and you should feel free to use any
of the classes which aren't marked @api private in your own codebase.

Is there a reason you aren't using Berkshelf for this? The use that you
are describing is 100% supported and something that I use in my projects
everyday. (overriding the locations of the dependencies found in the
metadata)

--
Jamie Winsor
@resetexistence
reset (Jamie Stormbreaker) · GitHub

On Wednesday, January 9, 2013 at 2:31 PM, Mike wrote:

Has someone done something like this already?

Um, berkshelf. :slight_smile:

You can probably figure out some of the work from there. But I have no
idea if the Chef cookbook metadata parser will allow for anything
other than a version string following a cookbook name.

Ref:
chef/chef/lib/chef/cookbook/metadata.rb at 10-stable · chef/chef · GitHub

-M

On Wed, Jan 9, 2013 at 5:26 PM, Torben Knerr ukio@gmx.de wrote:

Background:

First, I want to emulate Berkshelfs 'metadata' keyword inside a librarian
Cheffile.

Then I want to override the location for some of the metadata-defined
cookbook dependencies in the Cheffile (e.g. use github branch rather than
community site)

Has someone done something like this already?

Am 09.01.2013 22:44 schrieb "Torben Knerr" ukio@gmx.de:

Ohai Chefs,

what's the easiest way to obtain the cookbook dependencies defined in
metadata.rb (only direct dependencies are required)?

I'm not too firm with the chef internals yet, thus my first idea was to
evaluate metadata.rb and recording the depends calls via method_missing

  • but this doesn't feels quite right...

Thanks!
Torben

On Jan 9, 2013, at 5:47 PM, Jamie Winsor jamie@vialstudios.com wrote:

Is there a reason you aren't using Berkshelf for this? The use that you are describing is 100% supported and something that I use in my projects everyday. (overriding the locations of the dependencies found in the metadata)

Berkshelf is also pretty easy to extend as well. We wrote some company specific location handler and that was rather painless.

--bakins

Just to back it up a bit, if you really just need the dependencies from the metadata.rb, you can read a file as a Chef::Cookbook::Metadata and call .dependencies() off of it in 3 or 4 lines of code (more with error checking). Here's an example (lines 68-70 and 83)

Thanks,
Matt Ray
Senior Technical Evangelist | Opscode Inc.
matt@opscode.com | (512) 731-2218
Twitter, IRC, GitHub: mattray


From: Torben Knerr [ukio@gmx.de]
Sent: Wednesday, January 09, 2013 5:12 PM
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Re: How to obtain cookbook dependencies from metadata.rb?

Hey Mike, Jamie,

Thanks for the replies!

The knockout requirement for librarian in my specific case is http_proxy support.

I would go for Berkshelf just because of 'metadata' otherwise.
Both are great tools, librarian with a focus on simplicity and Berkshelf supporting more workflow-like stuff. I like both equally, but neither fully supports my current case :wink:

Cheers, Torben

Am 09.01.2013 23:47 schrieb "Jamie Winsor" <jamie@vialstudios.commailto:jamie@vialstudios.com>:
Hey Torben,

If you're familiar with Ruby you should be able to read the Berkshelf source to get an idea of how I implemented the metadata keyword. The Berkshelf code base is pretty friendly and you should feel free to use any of the classes which aren't marked @api private in your own codebase.

Is there a reason you aren't using Berkshelf for this? The use that you are describing is 100% supported and something that I use in my projects everyday. (overriding the locations of the dependencies found in the metadata)

--
Jamie Winsor
@resetexistence

On Wednesday, January 9, 2013 at 2:31 PM, Mike wrote:

Has someone done something like this already?
Um, berkshelf. :slight_smile:

You can probably figure out some of the work from there. But I have no
idea if the Chef cookbook metadata parser will allow for anything
other than a version string following a cookbook name.

Ref: https://github.com/opscode/chef/blob/10-stable/chef/lib/chef/cookbook/metadata.rb#L252-L267

-M

On Wed, Jan 9, 2013 at 5:26 PM, Torben Knerr <ukio@gmx.demailto:ukio@gmx.de> wrote:
Background:

First, I want to emulate Berkshelfs 'metadata' keyword inside a librarian
Cheffile.

Then I want to override the location for some of the metadata-defined
cookbook dependencies in the Cheffile (e.g. use github branch rather than
community site)

Has someone done something like this already?

Am 09.01.2013 22tel:09.01.2013%2022:44 schrieb "Torben Knerr" <ukio@gmx.demailto:ukio@gmx.de>:

Ohai Chefs,

what's the easiest way to obtain the cookbook dependencies defined in
metadata.rb (only direct dependencies are required)?

I'm not too firm with the chef internals yet, thus my first idea was to
evaluate metadata.rb and recording the depends calls via method_missing

  • but this doesn't feels quite right...

Thanks!
Torben

Hi all, thanks, that helped a lot.

@Matt Ray: I was missing the .from_file bit which came from the mixin,
thanks!

Torben

On Thu, Jan 10, 2013 at 4:07 PM, Matt Ray matt@opscode.com wrote:

Just to back it up a bit, if you really just need the dependencies from
the metadata.rb, you can read a file as a Chef::Cookbook::Metadata and call
.dependencies() off of it in 3 or 4 lines of code (more with error
checking). Here's an example (lines 68-70 and 83)

spiceweasel/lib/spiceweasel/cookbooks.rb at master · mattray/spiceweasel · GitHub

Thanks,
Matt Ray
Senior Technical Evangelist | Opscode Inc.
matt@opscode.com | (512) 731-2218
Twitter, IRC, GitHub: mattray

From: Torben Knerr [ukio@gmx.de]
Sent: Wednesday, January 09, 2013 5:12 PM
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Re: How to obtain cookbook dependencies
from metadata.rb?

Hey Mike, Jamie,

Thanks for the replies!

The knockout requirement for librarian in my specific case is http_proxy
support.

I would go for Berkshelf just because of 'metadata' otherwise.
Both are great tools, librarian with a focus on simplicity and Berkshelf
supporting more workflow-like stuff. I like both equally, but neither fully
supports my current case :wink:

Cheers, Torben

Am 09.01.2013 23:47 schrieb "Jamie Winsor" jamie@vialstudios.com:

Hey Torben,

If you're familiar with Ruby you should be able to read the Berkshelf
source to get an idea of how I implemented the metadata keyword. The
Berkshelf code base is pretty friendly and you should feel free to use any
of the classes which aren't marked @api private in your own codebase.

Is there a reason you aren't using Berkshelf for this? The use that you
are describing is 100% supported and something that I use in my projects
everyday. (overriding the locations of the dependencies found in the
metadata)

--
Jamie Winsor
@resetexistence
reset (Jamie Stormbreaker) · GitHub

On Wednesday, January 9, 2013 at 2:31 PM, Mike wrote:

Has someone done something like this already?

Um, berkshelf. :slight_smile:

You can probably figure out some of the work from there. But I have no
idea if the Chef cookbook metadata parser will allow for anything
other than a version string following a cookbook name.

Ref:
chef/chef/lib/chef/cookbook/metadata.rb at 10-stable · chef/chef · GitHub

-M

On Wed, Jan 9, 2013 at 5:26 PM, Torben Knerr ukio@gmx.de wrote:

Background:

First, I want to emulate Berkshelfs 'metadata' keyword inside a
librarian
Cheffile.

Then I want to override the location for some of the metadata-defined
cookbook dependencies in the Cheffile (e.g. use github branch rather than
community site)

Has someone done something like this already?

Am 09.01.2013 22:44 schrieb "Torben Knerr" ukio@gmx.de:

Ohai Chefs,

what's the easiest way to obtain the cookbook dependencies defined in
metadata.rb (only direct dependencies are required)?

I'm not too firm with the chef internals yet, thus my first idea was to
evaluate metadata.rb and recording the depends calls via
method_missing

  • but this doesn't feels quite right...

Thanks!
Torben