Class: Loom::Runner

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/loom/runner.rb

Constant Summary collapse

PatternExecutionError =
Class.new Loom::LoomError
FailFastExecutionError =
Class.new PatternExecutionError

Constants included from DSL

DSL::SSHConnectionError, DSL::UnexpectedHostError

Instance Method Summary collapse

Methods included from DSL

#on_host

Constructor Details

#initialize(loom_config, pattern_slugs = [], other_facts = {}) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/loom/runner.rb', line 9

def initialize(loom_config, pattern_slugs=[], other_facts={})
  @pattern_slugs = pattern_slugs
  @loom_config = loom_config
  @other_facts = other_facts

  @run_failures = []
  @result_reports = []

  # these are initialized in +load+
  @inventory_list = nil
  @active_hosts = nil
  @pattern_refs = nil
  @mod_loader = nil

  Loom.log.debug1(self) do
    "initialized runner with config => #{loom_config.dump}"
  end

  @caught_sig_int = false
end

Instance Method Details

#run(dry_run) ⇒ Object



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
64
65
66
67
68
69
70
71
72
73
# File 'lib/loom/runner.rb', line 30

def run(dry_run)
  install_signal_traps

  begin
    load

    if @pattern_refs.empty?
      Loom.log.warn "no patterns given, there's no work to do"
      return
    end
    if @active_hosts.empty?
      Loom.log.warn "no hosts in the active inventory"
      return
    end

    hostnames = @active_hosts.map(&:hostname)
    Loom.log.info do
      "executing patterns #{@pattern_slugs} across hosts #{hostnames}"
    end

    run_internal dry_run

    unless @run_failures.empty?
      raise PatternExecutionError, @run_failures
    end
  rescue Loom::Trap::SignalExit => e
    Loom.log.error "exiting on signal  => #{e.signal}"
    # Exit with the signal code or 40 for unknown Signal
    code = Signal.list[e.signal] || 40
    exit code
  rescue PatternExecutionError => e
    num_patterns_failed = @run_failures.size
    Loom.log.error "error executing #{num_patterns_failed} patterns => #{e}"
    Loom.log.debug e.backtrace.join "\n"
    exit 100 + num_patterns_failed
  rescue Loom::LoomError => e
    Loom.log.error "loom error => #{e.inspect}"
    exit 98
  rescue => e
    Loom.log.fatal "fatal error => #{e.inspect}"
    Loom.log.fatal e.backtrace.join "\n\t"
    exit 99
  end
end