Skip to content

Instantly share code, notes, and snippets.

@mariussturm
Created March 18, 2014 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariussturm/9616232 to your computer and use it in GitHub Desktop.
Save mariussturm/9616232 to your computer and use it in GitHub Desktop.
Apply librarian-chef's cookbook versions to a Chef environment
require "ridley"
require "librarian/chef"
Celluloid.logger = nil
namespace :chef do
desc "Apply cookbook verions from librarian-chef's lockfile to a chef environment"
task :apply, :environment do |t, args|
write_chef_environment(args.environment, librarian_locked_verions)
end
def librarian_locked_verions
versions = {}
e = Librarian::Chef::Environment.new
e.lock.manifests_index.each do |dep|
versions[dep[0]] = "= #{dep[1].version.to_s}"
end
return versions
end
def write_chef_environment(env, versions)
Ridley.open(server_url: ENV['CHEF_SERVER_URL'],
client_name: ENV['CHEF_USER_NAME'],
client_key: ENV['CHEF_CLIENT_KEY'],
ssl: {verify: false}) do |connection|
environment = connection.environment.find(env)
raise EnvironmentNotFound.new(name) if environment.nil?
environment.cookbook_versions = versions
environment.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment