Created
February 6, 2014 02:43
-
-
Save sneal/8837600 to your computer and use it in GitHub Desktop.
Script to generate a new Chef environment file using the latest cookbook versions from your Chef Server
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 'json' | |
env_name = ARGV[0] | |
raise "environment name is a required parameter" unless env_name | |
environment = Hash.new | |
environment[:name] = env_name | |
environment[:description] = "The #{env_name} environment" | |
cookbook_versions = Hash.new | |
`knife cookbook list`.split("\n").each do |line| | |
cookbook_parts = line.strip.split(/\s+/) | |
cookbook_versions[cookbook_parts[0]] = cookbook_parts[1] | |
end | |
environment[:cookbook_versions] = cookbook_versions | |
environment[:json_class] = "Chef::Environment" | |
environment[:chef_type] = "environment" | |
environment[:default_attributes] = Hash.new | |
environment[:override_attributes] = Hash.new | |
puts JSON.pretty_generate(environment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment