Created
May 12, 2011 05:21
-
-
Save rcreasey/967980 to your computer and use it in GitHub Desktop.
Using data bags with chef-solo
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
From: Brian Akins < [email protected]> | |
To: chef < [email protected]> | |
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