Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.