lib/opsworks/cli/subcommands/chef.rb in opsworks-cli-0.4.5 vs lib/opsworks/cli/subcommands/chef.rb in opsworks-cli-0.5.0
- old
+ new
@@ -1,14 +1,11 @@
-require 'aws'
require 'opsworks/stack'
module OpsWorks
module CLI
module Subcommands
module Chef
- # rubocop:disable MethodLength
- # rubocop:disable CyclomaticComplexity
def self.included(thor)
thor.class_eval do
desc 'chef:configure [--stack STACK]', 'Configure Chef/Berkshelf'
option :stack, type: :array
option :version, default: OpsWorks::Stack.latest_chef_version
@@ -18,11 +15,10 @@
option :cookbook_branch
option :cookbook_s3_url
option :cookbook_username
option :cookbook_password
define_method 'chef:configure' do
- fetch_credentials unless env_credentials?
stacks = parse_stacks(options.merge(active: true))
stacks.each do |stack|
say "Configuring Chef #{options[:version]} on #{stack.name}..."
stack.update_chef(options)
end
@@ -30,28 +26,31 @@
desc 'chef:sync [--stack STACK]', 'Sync OpsWorks custom cookbooks'
option :stack, type: :array
option :timeout, type: :numeric, default: 300
define_method 'chef:sync' do
- fetch_credentials unless env_credentials?
stacks = parse_stacks(options.merge(active: true))
deployments = stacks.map do |stack|
say "Syncing #{stack.name}..."
- stack.update_custom_cookbooks
+ dpl = stack.update_custom_cookbooks
+ next unless dpl
+ [stack, dpl]
+ end.compact
+
+ OpsWorks::Deployment.wait(deployments.map(&:last),
+ options[:timeout])
+
+ failures = deployments.map do |stack, deployment|
+ next if deployment.success?
+ stack
+ end.compact
+
+ unless failures.empty?
+ raise "Deploy failed on #{failures.map(&:name).join(', ')}"
end
- OpsWorks::Deployment.wait(deployments, options[:timeout])
- unless deployments.all?(&:success?)
- failures = []
- deployments.each_with_index do |deployment, i|
- failures << stacks[i].name unless deployment.success?
- end
- fail "Update failed on #{failures.join(', ')}"
- end
end
end
end
- # rubocop:enable CyclomaticComplexity
- # rubocop:enable MethodLength
end
end
end
end