[chef] Re: Data bag implementation for chef-solo


Chronological Thread 
  • From: "Ryan C. Creasey" < >
  • To: < >
  • Subject: [chef] Re: Data bag implementation for chef-solo
  • Date: Tue, 1 Feb 2011 07:51:24 -0800

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[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






Archive powered by MHonArc 2.6.16.

§