pec2 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pec2/pssh.rb +36 -23
- data/lib/pec2/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33e2d6953534f1dbc33754e2c61a0590562b28b8
|
4
|
+
data.tar.gz: 2d6b953f43d8dbedb76769e98e565300d9a08044
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33926a7b625ad0f58e5ad5022255c1845bc3bd538a96849fcf031604c30cb6e76caac04e3f9ce8ca308b8da77ffc66ee5bd0790816d5bc5dda70de2cc7f73cde
|
7
|
+
data.tar.gz: c117a938f7a882ce16d011ac6593a6b263b7cca3e9df4380519d7614c60c0b951ca62df24323d757e32bfcee3eff18bf0a74db10632f46b8a2821d5719ecd26c
|
data/lib/pec2/pssh.rb
CHANGED
@@ -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
|
-
|
38
|
-
Parallel.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/pec2/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|