Class: Moose::Inventory::Operations::AddGroups

Inherits:
Object
  • Object
show all
Includes:
OperationEventSupport
Defined in:
lib/moose_inventory/operations/add_groups.rb

Overview

Adds groups and their optional host associations.

Constant Summary collapse

AUTOMATIC_GROUP =
'ungrouped'

Instance Method Summary collapse

Constructor Details

#initialize(context:) ⇒ AddGroups

Returns a new instance of AddGroups.



14
15
16
# File 'lib/moose_inventory/operations/add_groups.rb', line 14

def initialize(context:)
  @context = context
end

Instance Method Details

#call(names:, hosts:, dry_run: false) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/moose_inventory/operations/add_groups.rb', line 18

def call(names:, hosts:, dry_run: false)
  events = []
  warning_count = 0
  @dry_run = dry_run

  if dry_run
    names.each do |name|
      warning_count += add_group(name, hosts, events)
    end
    emit(events, :dry_run_summary)
    return operation_result(events: events, warning_count: warning_count)
  end

  context.transaction do
    names.each do |name|
      warning_count += add_group(name, hosts, events)
    end
  end

  operation_result(events: events, warning_count: warning_count)
end