-
-
Save jjasghar/9894634 to your computer and use it in GitHub Desktop.
This file contains hidden or 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