jossh 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ada7289fa9d9e80eaeb6138d9db717288b39714e
4
- data.tar.gz: 7bb2c4f1460ccbe880855196de4a7ff6d646b472
3
+ metadata.gz: 2392f4c98b9c8a6d7ccb5bc0480485e3b8caaf10
4
+ data.tar.gz: 76699c16469e9855283b62b88a4edf842e80194c
5
5
  SHA512:
6
- metadata.gz: 7f7cec75732678fe5cab4c149d713b49b93829d0a2031f899bc88aeb8e70515de2009f10f230c8990b5fc661a8db50704f3d96094488fb0166724751a8af359c
7
- data.tar.gz: 70e7cf9f993aa127938db51eaa595bc277087633fa0a6d55ff83d3197f6d974d31a954329c429ed26319951da534895c2dc8360d606a32c51b805323e909c3ab
6
+ metadata.gz: de3c0205fb8da77a2f3f4ec794e9711ef0a97bd4b2ba1597ec146098378cd441bcb2fe0a93fee412fb474d0f9594fdb6b19b5599122128e91a8de8df3cc960d8
7
+ data.tar.gz: 50559ec6d9797dec802eeb81390f9d0f6c85dbb6570444108b07506a052de8b0168ebe08616b53bc25407f7cf1ee6778ba64917e7c84fb81c4fa9e7e7335147f
data/README.md CHANGED
@@ -8,7 +8,7 @@ Jossh - Your SSH Buddy
8
8
 
9
9
  **Jossh** is
10
10
 
11
- - a command line utility for running local scripts and comments over SSH.
11
+ - a command line utility for running local scripts and commands over SSH.
12
12
  - a ruby library for easier and prettier SSH deployment and automation.
13
13
 
14
14
  ## Install
@@ -25,14 +25,15 @@ Or install manually
25
25
  ## Features
26
26
 
27
27
  1. Allows running one or more commands over SSH.
28
- 2. Allows running external local scripts remotely
29
- 3. Has four commands: `ssh`, `ssh!`, `ssh_script` and `ssh_script!`. The 'bang' versions generate pretty and indented output.
30
- 4. Uses a single SSH connection.
31
- 5. Uses a simple hash for defining hosts.
32
- 6. Allows storing host specifications in a YAML file.
33
- 7. Supports all options available in `Net::SSH#start`.
34
- 8. Prints output Heroku-style.
35
- 9. Provides a command line interface - `jossh <host> <script>`
28
+ 2. Allows running local scripts remotely
29
+ 3. Allows running a script on multiple hosts.
30
+ 4. Has four commands: `ssh`, `ssh!`, `ssh_script` and `ssh_script!`. The 'bang' versions generate pretty and indented output.
31
+ 5. Uses a single SSH connection.
32
+ 6. Uses a simple hash for defining hosts.
33
+ 7. Allows storing host specifications in a YAML file.
34
+ 8. Supports all options available in `Net::SSH#start`.
35
+ 9. Prints output Heroku-style.
36
+ 10. Has a command line interface - `jossh <host> <script>`
36
37
 
37
38
  ## Command Line Usage
38
39
 
@@ -42,46 +43,47 @@ commands or a local script over SSH.
42
43
  $ jossh -h
43
44
 
44
45
  Jossh
45
-
46
+
46
47
  Usage:
47
48
  jossh <host> <script> [-- <arguments>...]
48
49
  jossh -m | --make-hostfile
49
50
  jossh -e | --edit-hostfile
50
51
  jossh -l | --list
51
- jossh -h | --help
52
+ jossh -h | --help
52
53
  jossh -v | --version
53
-
54
+
54
55
  Arguments:
55
56
  <host>
56
57
  can be:
57
- - :symbol : in this case we will look in ./ssh_hosts.yml
58
+ - :symbol : in this case we will look in ./ssh_hosts.yml or ~/ssh_hosts.yml
58
59
  - host : in this case we will use the current logged in user
59
60
  - user@host
60
-
61
- <script>
61
+
62
+ <script>
62
63
  can be:
63
64
  - a filename
64
65
  - one or more direct command
65
-
66
+
66
67
  <arguments>...
67
68
  When specifying a filename as the <script>, you may also pass additional
68
- arguments to it.
69
+ arguments to it.
69
70
  Use $1 - $9 in your script file to work with these arguments.
70
71
  Use $@ (or $*) to use the entire arguments string
71
-
72
+
72
73
  Options:
73
- -m --make-hostfile Generate a template ssh_hosts.yml
74
+ -m --make-hostfile Generate a template ssh_hosts.yml
74
75
  -e --edit-hostfile Open the currently used ssh_hosts.yml file for editing
75
76
  -l --list Show hosts in ./ssh_hosts.yml or ~/ssh_hosts.yml
76
77
  -h --help Show this screen
77
78
  -v --version Show version
78
-
79
- Examples:
79
+
80
+ Examples:
80
81
  jossh :production "git status"
81
82
  jossh jack@server.com "cd ~ && ls -l"
82
83
  jossh server.com deploy
83
84
  jossh server.com rake -- db:migrate
84
85
 
86
+ ---
85
87
 
86
88
  ## Library Usage
87
89
 
@@ -138,7 +140,7 @@ echo "-> Done"
138
140
 
139
141
  See also: The [examples folder](https://github.com/DannyBen/jossh/tree/master/examples)
140
142
 
141
- ## Host specification file
143
+ ## Host Specification File
142
144
 
143
145
  When using a :symbol as the host name, Jossh will look for a YAML
144
146
  configuration file named `ssh_hosts.yml`. The file is expected to be either
@@ -162,4 +164,58 @@ You can ask Jossh to create a sample file for you by running:
162
164
 
163
165
  $ jossh --make-hostfile
164
166
 
167
+ ## Working with Multiple Hosts
168
+
169
+ Define multiple hosts in the `ssh_hosts.yml` file by simply providing an array
170
+ of other keys:
171
+
172
+ ```yaml
173
+ :web01:
174
+ :host: web01.server.com
175
+ :user: admin
176
+
177
+ :web02:
178
+ :host: web02.server.com
179
+ :user: admin
180
+
181
+ :production:
182
+ - :web01
183
+ - :web02
184
+ ```
185
+
165
186
  See [ssh_hosts.example.yml](https://github.com/DannyBen/jossh/blob/master/ssh_hosts.example.yml) as an example.
187
+
188
+ ## Writing Scripts
189
+
190
+ The scripts you execute with Jossh are simple shell scripts. These variables
191
+ are available to you inside the script:
192
+
193
+ ### `$1 - $9 and $@ or $*`
194
+
195
+ When running through the command line and using the
196
+ `jossh <host> <script> -- <arguments>` syntax, these variables hold the
197
+ arguments.
198
+
199
+ `$@` and `$*` hold the entire arguments string.
200
+
201
+ Example:
202
+ ```bash
203
+ # myscript
204
+ echo "-> Running requested rake task"
205
+ rake $@
206
+ ```
207
+
208
+ And call it with:
209
+ `$ jossh :host myscript -- db:migrate`
210
+
211
+
212
+
213
+ ### `%{key}`
214
+ When this syntax appears in your script, it will be replaced with any key
215
+ from the host configuration.
216
+
217
+ Example:
218
+ ```bash
219
+ echo "-> Migrating database on %{host}"
220
+ rake db:migrate
221
+ ```
@@ -71,7 +71,11 @@ module Jossh
71
71
  if runner.active_hostfile
72
72
  say "!txtgrn!Using: #{runner.active_hostfile}\n"
73
73
  runner.ssh_hosts.each do |key, spec|
74
- say " :#{key.to_s.ljust(14)} = !txtblu!#{spec[:user]}!txtrst!@!txtylw!#{spec[:host]}"
74
+ if spec.is_a? Hash
75
+ say " :#{key.to_s.ljust(14)} = !txtblu!#{spec[:user]}!txtrst!@!txtylw!#{spec[:host]}"
76
+ else
77
+ say " :#{key.to_s.ljust(14)} = !txtpur!#{spec.join '!txtrst!, !txtpur!'}"
78
+ end
75
79
  end
76
80
  else
77
81
  say "!txtred!Cannot find ssh_hosts.yml or ~/ssh_hosts.yml"
@@ -20,13 +20,12 @@ module Jossh
20
20
  callback ||= method :simple_puts
21
21
  script = script.join "\n" if script.is_a? Array
22
22
  hostspec = load_spec(hostspec) if hostspec.is_a? Symbol
23
- host = hostspec.delete :host
24
- user = hostspec.delete :user
25
-
26
- Net::SSH.start( host, user, hostspec ) do |ssh|
27
- ssh.exec! script do |_ch, stream, data|
28
- callback.call data, stream
23
+ if hostspec.is_a? Array
24
+ hostspec.each do |spec|
25
+ execute_ssh_script spec, script, callback
29
26
  end
27
+ else
28
+ execute_ssh_script hostspec, script, callback
30
29
  end
31
30
  end
32
31
 
@@ -63,6 +62,17 @@ module Jossh
63
62
 
64
63
  private
65
64
 
65
+ def execute_ssh_script(hostspec, script, callback)
66
+ script = script % hostspec
67
+ host = hostspec.delete :host
68
+ user = hostspec.delete :user
69
+ Net::SSH.start( host, user, hostspec ) do |ssh|
70
+ ssh.exec! script do |_ch, stream, data|
71
+ callback.call data, stream
72
+ end
73
+ end
74
+ end
75
+
66
76
  def simple_puts(data, stream)
67
77
  if stream == :stderr
68
78
  STDERR.puts data
@@ -72,7 +82,18 @@ module Jossh
72
82
  end
73
83
 
74
84
  def load_spec(key)
75
- ssh_hosts[key] or raise "Cannot find :#{key}"
85
+ hostspec = ssh_hosts[key]
86
+ return hostspec if hostspec.is_a? Hash
87
+ if hostspec.is_a? Array
88
+ hostspecs = []
89
+ hostspec.each do |inner_key|
90
+ inner_hostspec = load_spec(inner_key)
91
+ inner_hostspec or raise "Cannot find :#{inner_key} in :#{key}"
92
+ hostspecs << inner_hostspec
93
+ end
94
+ return hostspecs
95
+ end
96
+ raise "Cannot find :#{key}"
76
97
  end
77
98
 
78
99
  def load_ssh_hosts
@@ -11,7 +11,7 @@ Usage:
11
11
  Arguments:
12
12
  <host>
13
13
  can be:
14
- - :symbol : in this case we will look in ./ssh_hosts.yml
14
+ - :symbol : in this case we will look in ./ssh_hosts.yml or ~/ssh_hosts.yml
15
15
  - host : in this case we will use the current logged in user
16
16
  - user@host
17
17
 
data/lib/jossh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jossh
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jossh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-30 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -53,47 +53,61 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.5'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest
56
+ name: runfile
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.8'
61
+ version: '0.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '5.8'
68
+ version: '0.5'
69
69
  - !ruby/object:Gem::Dependency
70
- name: minitest-reporters
70
+ name: run-gem-dev
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.1'
75
+ version: '0.2'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.1'
82
+ version: '0.2'
83
83
  - !ruby/object:Gem::Dependency
84
- name: run-gem-dev
84
+ name: minitest
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.2'
89
+ version: '5.8'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.2'
96
+ version: '5.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest-reporters
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.1'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement