Created
February 19, 2011 06:53
-
-
Save timdiggins/834890 to your computer and use it in GitHub Desktop.
rake task to convert existing ruby roles to json
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
# ADD this to Rakefile and run it by issuing rake roles.to_json | |
ROLE_DIR = File.expand_path(File.join(TOPDIR, "roles")) | |
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 | |
# relates to Chef roles. see http://wiki.opscode.com/display/chef/Roles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tweaked this a bit after coming across it yesterday because I couldn't get the Rake task working initially, but I ended up just moving it to its own Ruby script for execution: https://gist.github.com/bmurtagh/0c3389e25837f76be17f
Hopefully it helps