Skip to content

Instantly share code, notes, and snippets.

@rcreasey
Created May 12, 2011 05:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rcreasey/967980 to your computer and use it in GitHub Desktop.
Save rcreasey/967980 to your computer and use it in GitHub Desktop.
Using data bags with chef-solo
From: Brian Akins < brian@akins.org>
To: chef < chef@lists.opscode.com>
Subject: [chef] Data bag implementation for chef-solo
Date: Tue, 1 Feb 2011 10:42:05 -0500
We often use chef-solo for quick testing, etc. 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