Created
January 30, 2013 15:54
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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