cast-ssh 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/Gemfile +1 -1
- data/README.md +52 -28
- data/lib/cast.rb +26 -3
- metadata +20 -21
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
YWExNDJjOGU3MTYzOWY1OWU1MzhhZGE5ZmU4ZjZjNDRjZTY3MzkyYjZiZGY2
|
10
|
-
ZTRiNzU0ZGQ3ODA1OTJjNzc0YmU0YzU4YmU1NzQ3OTM3YTAwOGRlNzI0ZjFl
|
11
|
-
MzNjNzI1YWNjNjhkNjQ4YzdjMTk2OTEwM2I4NmE1NGY3ZDkxNmQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MmYxMGMzYWQ5ODMzNDQ1OGIxOTNjNDc3NjJhZjM2ZGQwNzRkNWVkODUzZmZm
|
14
|
-
OThiODBlMGY3YzIxY2MxMDNjYTU1NWVlNmI0ZWEyMTJhMzdiZDIyNThkM2Qx
|
15
|
-
OWE4MjUwYzZmMGQ5MDA5MzZlYTM2MjdkNmRlMGM2ZDViZWI3MTY=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cceed46756626f5c4c561cf1f6d906db52030585
|
4
|
+
data.tar.gz: ea3828524600ca8e6f073b7b5de2da4d4b6e7ae6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f15fca12981a9c221f10e3d5a5975d4da9950afc192d89b0c5db69d3709cf913a4014cd3915bf30e353ad1038eb2be8233a7d0e037a4945f25664151ee56c0c
|
7
|
+
data.tar.gz: c873f60082c69d8c5bbac734243f4636db527e48f9e385e45c6fc7a9705b3227eaa54c637056cc67a2271ca9c3004fcfc4e104851e1ddcba0fd596adb42a75c2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -6,39 +6,47 @@ This is a Ruby gem that executes remote commands via ssh on groups of servers de
|
|
6
6
|
|
7
7
|
Grab the gem:
|
8
8
|
|
9
|
-
|
9
|
+
```bash
|
10
|
+
gem install cast-ssh
|
11
|
+
```
|
10
12
|
|
11
13
|
Create your group file at ~/.cast.yml, like this:
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
```yaml
|
16
|
+
group1:
|
17
|
+
- host1
|
18
|
+
- host2
|
19
|
+
- host3
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
group2:
|
22
|
+
- host1
|
23
|
+
- host4
|
24
|
+
- host5
|
25
|
+
```
|
22
26
|
|
23
27
|
Run commands in your shell:
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
```bash
|
30
|
+
cast group1 echo test
|
31
|
+
cast group1,group2 sudo whoami
|
32
|
+
cast -s group1,host4 df -h
|
33
|
+
```
|
28
34
|
|
29
35
|
The output from the second command will look something like this:
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
```
|
38
|
+
[cast] loading groups from ~/.cast.yml
|
39
|
+
[cast] running ssh host1 'sudo whoami'
|
40
|
+
[cast] running ssh host2 'sudo whoami'
|
41
|
+
[cast] running ssh host3 'sudo whoami'
|
42
|
+
[cast] running ssh host4 'sudo whoami'
|
43
|
+
[cast] running ssh host5 'sudo whoami'
|
44
|
+
[host3] root
|
45
|
+
[host1] root
|
46
|
+
[host2] root
|
47
|
+
[host5] root
|
48
|
+
[host4] root
|
49
|
+
```
|
42
50
|
|
43
51
|
Note that the commands are run in parallel, so the output may be out of order.
|
44
52
|
|
@@ -55,19 +63,29 @@ Note that the commands are run in parallel, so the output may be out of order.
|
|
55
63
|
|
56
64
|
### API
|
57
65
|
|
58
|
-
You can also access the same functionality from within Ruby.
|
66
|
+
You can also access the same functionality from within Ruby.
|
67
|
+
|
68
|
+
To include Cast in your code do:
|
69
|
+
```ruby
|
70
|
+
require 'cast'
|
71
|
+
```
|
72
|
+
|
73
|
+
The following methods are available:
|
59
74
|
|
60
75
|
* __Cast::remote__ host, cmd
|
61
76
|
|
62
77
|
Run a remote command on the given host, sending output to stdout.
|
63
78
|
|
64
|
-
* __Cast::local__ cmd,
|
79
|
+
* __Cast::local__ cmd, options = {} -> int
|
65
80
|
|
66
81
|
Run a command locally, printing stdout and stderr from the command. Returns the process' return value.
|
67
82
|
|
68
|
-
|
69
|
-
|
70
|
-
|
83
|
+
You can use the following options:
|
84
|
+
```
|
85
|
+
:ensure - Raise exceptions if the command returns a non-zero error code.
|
86
|
+
:prefix - Prefix to use on lines when printing stdout/stderr.
|
87
|
+
:clean_bundler_env - Use a clean bundler environment when running the command.
|
88
|
+
```
|
71
89
|
|
72
90
|
* __Cast::log__ msg, source = 'cast', stream = $stdout
|
73
91
|
|
@@ -81,3 +99,9 @@ You can also access the same functionality from within Ruby. The following metho
|
|
81
99
|
|
82
100
|
Takes an array of groups and hosts, and expands the groups into their constituents given the input group hash. If no hash is given, use the value loaded most recently in load_groups. Returns an array of hostnames.
|
83
101
|
|
102
|
+
#### TODO
|
103
|
+
|
104
|
+
* Accept env vars for local and remote commands.
|
105
|
+
* Check for duplicate groups in groupfile.
|
106
|
+
* Propogate local signals to remote commands.
|
107
|
+
|
data/lib/cast.rb
CHANGED
@@ -2,12 +2,13 @@ require 'thread'
|
|
2
2
|
require 'open3'
|
3
3
|
require 'yaml'
|
4
4
|
require 'peach'
|
5
|
+
require 'bundler'
|
5
6
|
|
6
7
|
STDOUT.sync = true
|
7
8
|
STDERR.sync = true
|
8
9
|
|
9
10
|
module Cast
|
10
|
-
VERSION = '0.1.
|
11
|
+
VERSION = '0.1.5'
|
11
12
|
DEFAULTGROUPS = '~/.cast.yml'
|
12
13
|
|
13
14
|
@@mux = Mutex.new
|
@@ -76,10 +77,18 @@ module Cast
|
|
76
77
|
return r
|
77
78
|
end
|
78
79
|
|
79
|
-
def self.local cmd,
|
80
|
+
def self.local cmd, options = {}
|
81
|
+
prefix = nil
|
82
|
+
|
83
|
+
if options.is_a? String
|
84
|
+
prefix = options # this is for backwards compatibility
|
85
|
+
elsif options[:prefix]
|
86
|
+
prefix = options[:prefix]
|
87
|
+
end
|
88
|
+
|
80
89
|
r = nil
|
81
90
|
|
82
|
-
|
91
|
+
blk = Proc.new do |stdin, stdout, stderr, wait_thr|
|
83
92
|
@@pids << wait_thr.pid
|
84
93
|
stdin.close
|
85
94
|
|
@@ -118,6 +127,20 @@ module Cast
|
|
118
127
|
r = wait_thr.value
|
119
128
|
end
|
120
129
|
|
130
|
+
if options[:clean_bundler_env]
|
131
|
+
Bundler.with_clean_env do
|
132
|
+
Open3.popen3(cmd, &blk)
|
133
|
+
end
|
134
|
+
else
|
135
|
+
Open3.popen3(cmd, &blk)
|
136
|
+
end
|
137
|
+
|
138
|
+
if options[:ensure]
|
139
|
+
unless r.exitstatus == 0
|
140
|
+
raise "command failed: #{cmd}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
121
144
|
return r.exitstatus
|
122
145
|
end
|
123
146
|
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Bakkum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mocha
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: autotest-standalone
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: peach
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: trollop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: Execute remote commands via ssh on groups of machines
|
@@ -90,14 +90,14 @@ extra_rdoc_files:
|
|
90
90
|
- LICENSE.md
|
91
91
|
- README.md
|
92
92
|
files:
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
93
96
|
- LICENSE.md
|
94
97
|
- README.md
|
98
|
+
- bin/cast
|
95
99
|
- cast.gemspec
|
96
|
-
- Gemfile
|
97
|
-
- .rspec
|
98
|
-
- .travis.yml
|
99
100
|
- lib/cast.rb
|
100
|
-
- bin/cast
|
101
101
|
- spec/lib/cast_spec.rb
|
102
102
|
- spec/spec_helper.rb
|
103
103
|
- spec/test.yml
|
@@ -107,22 +107,22 @@ licenses:
|
|
107
107
|
metadata: {}
|
108
108
|
post_install_message:
|
109
109
|
rdoc_options:
|
110
|
-
- --charset=UTF-8
|
110
|
+
- "--charset=UTF-8"
|
111
111
|
require_paths:
|
112
112
|
- lib
|
113
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
|
-
- -
|
120
|
+
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: 1.3.6
|
123
123
|
requirements: []
|
124
124
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.2.2
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Execute remote commands via ssh on groups of machines
|
@@ -130,4 +130,3 @@ test_files:
|
|
130
130
|
- spec/lib/cast_spec.rb
|
131
131
|
- spec/spec_helper.rb
|
132
132
|
- spec/test.yml
|
133
|
-
has_rdoc:
|