Module: OpsWorks::CLI::Subcommands::Exec

Included in:
Agent
Defined in:
lib/opsworks/cli/subcommands/exec.rb

Class Method Summary collapse

Class Method Details

.included(thor) ⇒ Object

rubocop:disable MethodLength rubocop:disable CyclomaticComplexity



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/opsworks/cli/subcommands/exec.rb', line 9

def self.included(thor)
  thor.class_eval do
    desc 'exec [--stack STACK] RECIPE', '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