Created
March 18, 2014 09:00
-
-
Save mariussturm/9616232 to your computer and use it in GitHub Desktop.
Apply librarian-chef's cookbook versions to a Chef environment
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 "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