pec2 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pec2/pssh.rb +36 -23
  3. data/lib/pec2/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d212e880ee55a9fd7282d28c16d77b9435019b3
4
- data.tar.gz: 582aa6fd904cc9a75ec0d6a2063706ceada859d7
3
+ metadata.gz: 33e2d6953534f1dbc33754e2c61a0590562b28b8
4
+ data.tar.gz: 2d6b953f43d8dbedb76769e98e565300d9a08044
5
5
  SHA512:
6
- metadata.gz: ba417870100d95967e9df7dcbcd501bb7e15e81905554295d1a2acaa1ff732a45424c69903cb1f19510009dd66ff56812943db26526e99821664829639ba7053
7
- data.tar.gz: 7cc2a92acc8c92ab9b96235e32765bb86e8e89928b2abef6ae554d549425c36db6e4ef33101d707698e597da0feeb3e575ddf63e99c1a90a64ddf44df0de6ad9
6
+ metadata.gz: 33926a7b625ad0f58e5ad5022255c1845bc3bd538a96849fcf031604c30cb6e76caac04e3f9ce8ca308b8da77ffc66ee5bd0790816d5bc5dda70de2cc7f73cde
7
+ data.tar.gz: c117a938f7a882ce16d011ac6593a6b263b7cca3e9df4380519d7614c60c0b951ca62df24323d757e32bfcee3eff18bf0a74db10632f46b8a2821d5719ecd26c
@@ -34,37 +34,50 @@ module Pec2
34
34
 
35
35
  def exec_pssh_command(command)
36
36
  return false if command.nil? || command.empty?
37
- error_servers = []
38
- Parallel.each(@servers, in_threads: @parallel) do |server|
39
- begin
40
- Net::SSH.start(server[:host], @user, @ssh_options) do |ssh|
41
- channel = ssh.open_channel do |channel, success|
42
- channel.on_data do |channel, data|
43
- if data =~ /^\[sudo\] password for /
44
- channel.send_data "#{@sudo_password}\n"
45
- else
46
- data.to_s.lines.each do |line|
47
- if @print
48
- print %Q{#{server[:host]}:#{line}}.colorize(server[:color])
49
- end
37
+ exit_status = {}
38
+ Parallel.map(@servers, in_threads: @parallel) do |server|
39
+ exit_status[server[:host]] = exec_ssh(server, command)
40
+ end
41
+ errors = exit_status.select {|k, v| v != 0 }
42
+ if errors.size > 0
43
+ @logger.error "error servers => #{errors.keys.join(', ')}".colorize(:red)
44
+ return false
45
+ end
46
+ return true
47
+ end
48
+
49
+ private
50
+
51
+ def exec_ssh(server, command)
52
+ exit_code = nil
53
+ begin
54
+ Net::SSH.start(server[:host], @user, @ssh_options) do |ssh|
55
+ channel = ssh.open_channel do |channel, success|
56
+ channel.on_data do |channel, data|
57
+ if data =~ /^\[sudo\] password for /
58
+ channel.send_data "#{@sudo_password}\n"
59
+ else
60
+ data.to_s.lines.each do |line|
61
+ if @print
62
+ print %Q{#{server[:host]}:#{line}}.colorize(server[:color])
50
63
  end
51
64
  end
52
65
  end
53
- channel.request_pty
54
- channel.exec(command)
55
- channel.wait
66
+ end
67
+ channel.request_pty
68
+ channel.exec(command) do |ch, success|
69
+ channel.on_request("exit-status") do |ch,data|
70
+ exit_code = data.read_long
71
+ end
56
72
  end
57
73
  channel.wait
58
74
  end
59
- rescue => e
60
- error_servers << server[:host]
61
- puts "\n#{e.message}\n#{e.backtrace.join("\n")}"
75
+ channel.wait
62
76
  end
77
+ rescue => e
78
+ puts "\n#{e.message}\n#{e.backtrace.join("\n")}"
63
79
  end
64
- if error_servers.size > 0
65
- @logger.error "error servers => #{error_servers.join(', ')}".colorize(:red)
66
- end
67
- return true
80
+ return exit_code
68
81
  end
69
82
  end
70
83
  end
@@ -1,4 +1,4 @@
1
1
  module Pec2
2
2
  # pec2 version
3
- VERSION = "0.6.1"
3
+ VERSION = "0.6.2"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - toyama0919
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor