Module: OpsWorks::CLI::Subcommands::Recipes
- Included in:
- Agent
- Defined in:
- lib/opsworks/cli/subcommands/recipes.rb
Class Method Summary collapse
-
.included(thor) ⇒ Object
rubocop:disable MethodLength rubocop:disable CyclomaticComplexity.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/opsworks/cli/subcommands/recipes.rb', line 9 def self.included(thor) thor.class_eval do desc 'recipes:run RECIPE [--stack STACK]', 'Execute a Chef recipe' option :stack, type: :array option :timeout, type: :numeric, default: 300 define_method 'recipes:run' do |recipe| fetch_credentials unless env_credentials? stacks = parse_stacks(.merge(active: true)) deployments = stacks.map do |stack| say "Executing recipe on #{stack.name}..." stack.execute_recipe(recipe) end OpsWorks::Deployment.wait(deployments, [:timeout]) 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 desc 'recipes:add LAYER EVENT RECIPE [--stack STACK]', 'Add a recipe to a given layer and lifecycle event' option :stack, type: :array define_method 'recipes:add' do |layername, event, recipe| fetch_credentials unless env_credentials? stacks = parse_stacks() stacks.each do |stack| layer = stack.layers.find { |l| l.shortname == layername } next unless layer next if layer.custom_recipes[event].include?(recipe) say "Adding recipe to #{stack.name}." layer.add_custom_recipe(event, recipe) end end desc 'recipes:rm LAYER EVENT RECIPE [--stack STACK]', 'Remove a recipe from a given layer and lifecycle event' option :stack, type: :array define_method 'recipes:rm' do |layername, event, recipe| fetch_credentials unless env_credentials? stacks = parse_stacks() stacks.each do |stack| layer = stack.layers.find { |l| l.shortname == layername } next unless layer next unless layer.custom_recipes[event].include?(recipe) say "Removing recipe from #{stack.name}." layer.remove_custom_recipe(event, recipe) end end end end |