Class: Koma::Backend::Ssh

Inherits:
Base
  • Object
show all
Defined in:
lib/koma/backend/ssh.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#host, #inventory_keys, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #out

Constructor Details

This class inherits a constructor from Koma::Backend::Base

Instance Attribute Details

#stdinObject

Returns the value of attribute stdin.



7
8
9
# File 'lib/koma/backend/ssh.rb', line 7

def stdin
  @stdin
end

Instance Method Details

#gatherObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/koma/backend/ssh.rb', line 9

def gather
  if host.include?(',')
    list = host.split(',').uniq
    results = Parallel.map(list) do |h|
      gather_via_ssh(h, options)
    end
    arr = [list, results].transpose
    result = Hash[*arr.flatten]
  else
    result = gather_via_ssh(host, options)
  end
  result
end

#gather_via_ssh(host, options) ⇒ Object



37
38
39
40
# File 'lib/koma/backend/ssh.rb', line 37

def gather_via_ssh(host, options)
  set :ssh_options, build_ssh_options(host, options)
  out(options[:key])
end

#run_commands(commands) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/koma/backend/ssh.rb', line 23

def run_commands(commands)
  if host.include?(',')
    list = host.split(',').uniq
    results = Parallel.map(list) do |h|
      run_commands_via_ssh(h, options, commands)
    end
    arr = [list, results].transpose
    result = Hash[*arr.flatten]
  else
    result = run_commands_via_ssh(host, options, commands)
  end
  result
end

#run_commands_via_ssh(host, options, commands) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/koma/backend/ssh.rb', line 42

def run_commands_via_ssh(host, options, commands)
  set :ssh_options, build_ssh_options(host, options)
  results = {}
  commands.each do |command|
    result = Specinfra.backend.run_command(command)
    results[command] = {
      exit_signal: result.exit_signal,
      exit_status: result.exit_status,
      stderr: result.stderr,
      stdout: result.stdout
    }
  end
  results
end