Skip to content

Instantly share code, notes, and snippets.

@bmurtagh
Created March 18, 2015 14:01
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bmurtagh/0c3389e25837f76be17f to your computer and use it in GitHub Desktop.
Save bmurtagh/0c3389e25837f76be17f to your computer and use it in GitHub Desktop.
Convert Chef Ruby DSL Roles to JSON
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
@taimai
Copy link

taimai commented Oct 29, 2015

Very useful script. Thank you!

@muddman
Copy link

muddman commented Nov 10, 2015

extremely helpful -- thanks!

@gsaslis
Copy link

gsaslis commented Aug 16, 2016

@bmurtagh - dude, you rock!
thanks for sharing! : )

The pain of going to chef_zero from chef-solo has just been eased a little bit.

@necrux
Copy link

necrux commented Dec 11, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment