Skip to content

Instantly share code, notes, and snippets.

@mheffner
Created October 18, 2011 17:45
Show Gist options
  • Save mheffner/1296089 to your computer and use it in GitHub Desktop.
Save mheffner/1296089 to your computer and use it in GitHub Desktop.
Chef roles ruby->json rake task
ROLE_DIR = File.expand_path('../roles', __FILE__)
namespace :roles do
desc "Convert ruby roles from ruby to json, creating/overwriting json files."
task :to_json do
Dir.glob(File.join(ROLE_DIR, '*.rb')) do |rb_file|
role = Chef::Role.new
role.from_file(rb_file)
json_file = rb_file.sub(/\.rb$/,'.json')
File.open(json_file, 'w'){|f| f.write(JSON.pretty_generate(role))}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment