0.0
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
A Chef Knife plugin to convert Chef objects to ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 3.8
~> 0.9
= 2.99.0
= 2.99.0

Runtime

< 13.0, >= 11.0
 Project Readme

Knife To Ruby

A Chef Knife plugin to print Chef objects (Role/Environment) in ruby code,

$ knife role toruby role_name
name "role_name"

description "my description"

default_attributes({
  "a" => "b"
})

override_attributes({
  "a" => "b"
})

run_list("recipe[cookbook_a]", "recipe[cookbook_b]")

Should be equivalent to knife show role -Fj but for ruby.

Check the change log to see what has changed.

Installation

/opt/chef/embedded/gem install knife-toruby

How to Use

knife role toruby [ROLE]
knife environment toruby [ENVIRONMENT]

Chef Objects Supported

  • Role
  • Environment

Transform .json file to .rb locally

If you want to transform your .json role/environment files locally without uploading them to the chef-server you can do that using this script,

require 'chef/ruby_compat'
require 'chef/knife'
require 'chef/knife/core/object_loader'
require 'json'

loader = ::Chef::Knife::Core::ObjectLoader.new(Chef::Role, nil)
role = loader.load_from("roles", 'MY_ROLE.json')

puts Chef::RubyCompat.to_ruby(role)

Update this script with your file name and if you are using an environment instead of a role. Save this file as something like transform.rb, make sure to have knife-toruby installed in knife and then run the command,

knife exec transform.rb