Skip to content

Instantly share code, notes, and snippets.

@natlownes
Created January 30, 2013 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save natlownes/4674204 to your computer and use it in GitHub Desktop.
Save natlownes/4674204 to your computer and use it in GitHub Desktop.
rake task for dumping roles defined in the ruby DSL to json. expects dir .chef/chef_server_backup to exist in your chef-repo
namespace :roles do
desc 'dump roles defined in the Ruby DSL to json'
task :dump do
destination_dir = File.join(TOPDIR, '.chef', 'chef_server_backup')
files_paths = Dir["#{TOPDIR}/roles/*.rb"]
files_paths.each do |filename|
role_name = File.basename(filename, '.rb')
role = Chef::Role.new
role.name(role_name)
role.from_file(filename)
role
json_file_path = File.join(destination_dir, "#{role_name}.json")
File.open(json_file_path, 'w+') do |file|
file << role.to_json
puts "dumped #{role.name} to #{json_file_path}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment