Skip to content

Instantly share code, notes, and snippets.

@mpasternacki
Created September 1, 2011 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpasternacki/1185990 to your computer and use it in GitHub Desktop.
Save mpasternacki/1185990 to your computer and use it in GitHub Desktop.
Opscode Chef cookbook's metadata.rb fragment to pull cookbook dependencies out of data bag files.
# Data bag items in 'projects' can declare 'include_recipes' property
# (list or string); these recipes will be included in the
# projects::default recipe, but - if they're not already loaded - need
# to be declared in 'depends'. This code loads the data bag JSON from
# files, and declares all needed dependencies.
require 'json'
soft_deps = []
Dir[File.join( File.dirname(__FILE__),
'../../data_bags/projects/*.json' )].each do |p|
soft_deps |= File::open(p) { |f| JSON::load(f) }["include_recipes"].to_a.
map { |dep| dep.split('::').first }
end
# Don't depend on self or already declared cookbooks:
soft_deps -= [ 'base', 'mysql', 'nginx', 'sj_packages', 'projects' ]
soft_deps.each do |dep|
depends dep
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment