[chef] Re: Re: Re: Dynamically include recipes?


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: Re: Re: Dynamically include recipes?
  • Date: Tue, 11 Jan 2011 09:09:47 -0800

On Mon, Jan 10, 2011 at 6:29 PM, Ian Marlier 
< >
 wrote:
> What I had hoped to do was this:
> cookbooks = search(:cookbooks, "recipe:nagios")
> cookbooks.each do |c|
>     include_recipe "#{c}::nagios"
> end
> However, the search function doesn't appear to work on cookbooks.  I'm
> wondering if there's another way that I can do this.

You can't do this with search, but you can use the REST API. For
example, `knife exec 'pp api.get "cookbooks/_latest"` will print a
hash of COOKBOOK_NAME => CONONICAL_URL which you can iterate over to
get the contents of each cookbook. This will pretty print a hash of
COOKBOOK_NAME => [RECIPE] for each cookbook:

   knife exec -E '(api.get "cookbooks/_latest").each {|c, url| pp c =>
api.get(url).recipe_filenames}'

You could then filter that for the desired recipes. Note that outside
of shef/knife exec you need to use `get_rest` instead of just
`get`--shef aliases that method for brevity.


> If there's no way to do this within Chef, I can work around it, for example
> by doing some bash scripting at cookbook upload time -- though that would be
> disappointing, as it would effectively make this recipe only operable in
> certain chef server environments.  If there's a "real" way, that would be
> most excellent.

Despite the above, if you want to pursue the design you described
previously (having nagios recipes "sprinkled" throughout your cookbook
repo), your best bet is to do some analysis up front and modify your
nagios cookbook accordingly. Even if you can get the list of recipes
you want from the API, you still need their cookbooks to be listed in
the metadata for your nagios cookbook in order to have them synced to
the edge. If you try to do this from within a recipe, you'll need 2
chef runs to properly converge everything.


> - Ian

HTH,
Dan DeLeo



Archive powered by MHonArc 2.6.16.

§