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
I’m an old school C guy and I blame most of the code on a co-worker Use
at your own risk, will probably eat your hard drive, etc.
–Brian
1 Like
Heh, we were just talking about this in #vagrant the other day. This looks awesome; I'll try this out. Thanks!
--
Ryan C. Creasey
Principal Systems Engineer
Gamespy Technology
IGN Entertainment
On Feb 1, 2011, at 7:42 AM, Brian Akins wrote:
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
I'm an old school C guy and I blame most of the code on a co-worker Use at your own risk, will probably eat your hard drive, etc.
--Brian
thanks a lot! I needed this the other day.
– Thibaut
Feel free to file a ticket and patch Chef if this is useful for you.
Adam
On Tue, Feb 1, 2011 at 7:42 AM, Brian Akins brian@akins.org wrote:
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
I'm an old school C guy and I blame most of the code on a co-worker Use
at your own risk, will probably eat your hard drive, etc.
--Brian
--
Opscode, Inc.
Adam Jacob, Chief Product Officer
T: (206) 619-7151 E: adam@opscode.com
On Monday, February 7, 2011 at 10:26 AM, Thibaut Barrère wrote:
Did anyone file a ticket for that ? I'd like to vote for it.
I haven't seen a ticket, but as long as there are tests and CLAs are taken care of, we'd happily merge this.
Dan DeLeo
Yeah, it would be great to get this into Chef!
2011/2/1 Adam Jacob adam@opscode.com:
Feel free to file a ticket and patch Chef if this is useful for you.
Adam
On Tue, Feb 1, 2011 at 7:42 AM, Brian Akins brian@akins.org wrote:
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
I'm an old school C guy and I blame most of the code on a co-worker Use
at your own risk, will probably eat your hard drive, etc.
--Brian
--
Opscode, Inc.
Adam Jacob, Chief Product Officer
T: (206) 619-7151 E: adam@opscode.com
Did anyone file a ticket for that ? I'd like to vote for it.
-- Thibaut
On Wed, Feb 2, 2011 at 10:40 AM, Miquel Torres tobami@googlemail.comwrote:
Yeah, it would be great to get this into Chef!
2011/2/1 Adam Jacob adam@opscode.com:
Feel free to file a ticket and patch Chef if this is useful for you.
Adam
On Tue, Feb 1, 2011 at 7:42 AM, Brian Akins brian@akins.org wrote:
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
I'm an old school C guy and I blame most of the code on a co-worker
Use
at your own risk, will probably eat your hard drive, etc.
--Brian
--
Opscode, Inc.
Adam Jacob, Chief Product Officer
T: (206) 619-7151 E: adam@opscode.com