-
-
Save bmurtagh/0c3389e25837f76be17f to your computer and use it in GitHub Desktop.
Convert Chef Ruby DSL 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
require 'chef' | |
# Update path to reflect where your roles are stored | |
ROLE_DIR = "/Users/bmurtagh/chef-repo/roles" | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This little script is getting some use 4 years later @bmurtagh. Thanks!
I expanded on it a bit further as well:
https://github.com/necrux/chef-tools/blob/master/convert-chef-role.rb