Sha256: cc43f62054ac4ac1cec9be1feef9a7760355578242866c53bf824ed32242021b

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

require 'opsworks/deployment'

module OpsWorks
  module CLI
    module Subcommands
      module Exec
        # rubocop:disable MethodLength
        # rubocop:disable CyclomaticComplexity
        def self.included(thor)
          thor.class_eval do
            desc 'exec RECIPE [--stack STACK]', 'Execute a Chef recipe'
            option :stack, type: :array
            def exec(recipe)
              fetch_keychain_credentials unless env_credentials?
              stacks = parse_stacks(options.merge(active: true))
              deployments = stacks.map do |stack|
                say "Executing recipe on #{stack.name}..."
                stack.execute_recipe(recipe)
              end
              OpsWorks::Deployment.wait(deployments)
              unless deployments.all?(&:success?)
                failures = []
                deployments.each_with_index do |deployment, i|
                  failures << stacks[i].name unless deployment.success?
                end
                fail "Command failed on #{failures.join(', ')}"
              end
            end
          end
        end
        # rubocop:enable CyclomaticComplexity
        # rubocop:enable MethodLength
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opsworks-cli-0.2.4 lib/opsworks/cli/subcommands/exec.rb
opsworks-cli-0.2.3 lib/opsworks/cli/subcommands/exec.rb
opsworks-cli-0.2.2 lib/opsworks/cli/subcommands/exec.rb