Created
September 1, 2011 11:28
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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