Skip to content

Instantly share code, notes, and snippets.

@grantr
Created September 1, 2010 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantr/561457 to your computer and use it in GitHub Desktop.
Save grantr/561457 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'fileutils'
require 'chef'
pwd = File.dirname(__FILE__)
Chef::Config.from_file("/etc/chef/client.rb")
Chef::Config[:node_name] = ENV['OPSCODE_USER']
Chef::Config[:client_key] = ENV['OPSCODE_KEY']
Chef::Log::Formatter.show_time = false
Chef::Log.level(:error)
Mixlib::Authentication::Log.level(:error)
bags = Chef::DataBag.list
bags.each do |bag, bag_uri|
puts bag
FileUtils.mkdir_p(File.join(pwd, bag))
items = Chef::DataBag.load(bag)
items.each do |item, item_uri|
puts " #{item}"
fname = File.join(pwd, bag, item) + ".json"
if File.exists?(fname)
FileUtils.move(fname, fname + ".#{Time.now.strftime('%Y%m%d%H%M%S')}")
end
f = File.new(fname, "w")
f.write(JSON.pretty_generate(Chef::DataBagItem.load(bag, item)))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment