cast-ssh 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -4
- data/bin/cast +5 -1
- data/lib/cast.rb +13 -5
- metadata +2 -2
data/README.md
CHANGED
@@ -24,12 +24,16 @@ group2:
|
|
24
24
|
- host5
|
25
25
|
```
|
26
26
|
|
27
|
-
Run commands in your shell:
|
27
|
+
Run commands in your shell using this pattern:
|
28
|
+
```bash
|
29
|
+
cast [<flags>] <target> <command>
|
30
|
+
```
|
28
31
|
|
32
|
+
For example:
|
29
33
|
```bash
|
30
34
|
cast group1 echo test
|
31
35
|
cast group1,group2 sudo whoami
|
32
|
-
cast -s group1,host4 df -h
|
36
|
+
cast -s group1,host4 "df -h"
|
33
37
|
```
|
34
38
|
|
35
39
|
The output from the second command will look something like this:
|
@@ -40,11 +44,9 @@ The output from the second command will look something like this:
|
|
40
44
|
[cast] running ssh host2 'sudo whoami'
|
41
45
|
[cast] running ssh host3 'sudo whoami'
|
42
46
|
[cast] running ssh host4 'sudo whoami'
|
43
|
-
[cast] running ssh host5 'sudo whoami'
|
44
47
|
[host3] root
|
45
48
|
[host1] root
|
46
49
|
[host2] root
|
47
|
-
[host5] root
|
48
50
|
[host4] root
|
49
51
|
```
|
50
52
|
|
data/bin/cast
CHANGED
@@ -34,6 +34,7 @@ EOS
|
|
34
34
|
opt :list, 'Print out contents of groupfile without executing command', :short => 'l'
|
35
35
|
opt :clusters, 'Print out only groupnames without executing command', :short => 'c'
|
36
36
|
opt :ssh, 'SSH command to run', :default => 'ssh'
|
37
|
+
opt :strict, 'Return a non-zero exit code if ANY of the ssh commands exit non-zero', :short => 't'
|
37
38
|
end
|
38
39
|
|
39
40
|
opt = Trollop::with_standard_exception_handling p do
|
@@ -57,5 +58,8 @@ end
|
|
57
58
|
cmd = ARGV[1..-1].join(' ')
|
58
59
|
hosts = Cast::expand_groups ARGV[0].split(','), groups
|
59
60
|
|
60
|
-
Cast::run hosts, cmd, opt[:serial], opt[:delay], opt[:ssh]
|
61
|
+
result = Cast::run hosts, cmd, opt[:serial], opt[:delay], opt[:ssh], opt[:strict]
|
62
|
+
if opt[:strict] and not result
|
63
|
+
exit 1
|
64
|
+
end
|
61
65
|
|
data/lib/cast.rb
CHANGED
@@ -8,7 +8,7 @@ STDOUT.sync = true
|
|
8
8
|
STDERR.sync = true
|
9
9
|
|
10
10
|
module Cast
|
11
|
-
VERSION = '0.1.
|
11
|
+
VERSION = '0.1.8'
|
12
12
|
DEFAULTGROUPS = '~/.cast.yml'
|
13
13
|
|
14
14
|
@@mux = Mutex.new
|
@@ -51,24 +51,32 @@ module Cast
|
|
51
51
|
return hosts.uniq
|
52
52
|
end
|
53
53
|
|
54
|
-
def self.run hosts, cmd, serial = false, delay = nil, ssh = 'ssh'
|
54
|
+
def self.run hosts, cmd, serial = false, delay = nil, ssh = 'ssh', strict = false
|
55
|
+
success = true
|
55
56
|
if serial or delay
|
56
57
|
hosts.each_with_index do |host, i|
|
57
|
-
remote host, cmd, ssh
|
58
|
+
exitCode = remote host, cmd, ssh
|
59
|
+
if strict
|
60
|
+
success &&= (exitCode == 0)
|
61
|
+
end
|
58
62
|
if delay and i < hosts.size - 1
|
59
63
|
log "delay for #{delay} seconds"
|
60
64
|
sleep delay
|
61
65
|
end
|
62
66
|
end
|
63
67
|
else
|
64
|
-
hosts.
|
68
|
+
exitCodes = hosts.pmap { |host| remote host, cmd, ssh }
|
69
|
+
if strict
|
70
|
+
success = (exitCodes.reduce(:+) == 0)
|
71
|
+
end
|
65
72
|
end
|
73
|
+
return success
|
66
74
|
end
|
67
75
|
|
68
76
|
def self.remote host, cmd, ssh = 'ssh'
|
69
77
|
fullcmd = "#{ssh} #{host} '#{cmd}'"
|
70
78
|
log "running #{fullcmd}"
|
71
|
-
local fullcmd, {:prefix => host}
|
79
|
+
return local fullcmd, {:prefix => host}
|
72
80
|
end
|
73
81
|
|
74
82
|
def self.local cmd, options = {}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cast-ssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mocha
|