Skip to content

Instantly share code, notes, and snippets.

@jjasghar
Forked from natlownes/chef.rake
Created March 31, 2014 15:13
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 jjasghar/9894634 to your computer and use it in GitHub Desktop.
Save jjasghar/9894634 to your computer and use it in GitHub Desktop.
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