Skip to content

Instantly share code, notes, and snippets.

@thbar
Created February 1, 2011 16:54
Show Gist options
  • Save thbar/806137 to your computer and use it in GitHub Desktop.
Save thbar/806137 to your computer and use it in GitHub Desktop.
Provided by Brian Akins on the chef mailing list: "This is our extremely simple implementation of data bags for chef-solo. Add "data_bag_path /some/dir/data_bags" to your solo.rb and add this into your libraries"
if Chef::Config[:solo]
class Chef
module Mixin
module Language
def data_bag(bag)
@solo_data_bags = {} if @solo_data_bags.nil?
unless @solo_data_bags[bag]
@solo_data_bags[bag] = {}
Dir.glob(File.join(Chef::Config[:data_bag_path], bag,
"*.json")).each do |f|
item = JSON.parse(IO.read(f))
@solo_data_bags[bag][item['id']] = item
end
end
@solo_data_bags[bag].keys
end
def data_bag_item(bag, item)
data_bag(bag) unless (!@solo_data_bags.nil? && @solo_data_bags[bag])
@solo_data_bags[bag][item]
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment