Module: Jossh
- Defined in:
- lib/jossh/api.rb,
lib/jossh/version.rb,
lib/jossh/bin_handler.rb,
lib/jossh/command_runner.rb,
lib/jossh/output_handler.rb
Overview
API Methods
These are all the exposed commands.
Defined Under Namespace
Classes: BinHandler, CommandRunner, OutputHandler
Constant Summary collapse
- VERSION =
"0.1.5"
Instance Method Summary collapse
-
#ssh(hostspec, script, callback: nil) ⇒ Object
Execute one or more commands via SSH.
-
#ssh!(hostspec, script) ⇒ Object
Same as
ssh
, only this will print a pretty output. -
#ssh_hostfile(file) ⇒ Object
Set the name of the hostfile.
-
#ssh_script(hostspec, script, arguments: nil, callback: nil) ⇒ Object
Same as
ssh
, only load commands from a file. -
#ssh_script!(hostspec, script, arguments: nil) ⇒ Object
Same as
ssh_script
, only this will print a pretty output.
Instance Method Details
#ssh(hostspec, script, callback: nil) ⇒ Object
Execute one or more commands via SSH
Params:
hostspec
-
A hash of SSH host parameters or a symbol pointing to a record in
ssh_hosts.yml
. If a hash is provided, it must include at least:host
and:user
. It can also include any or the options supported by Net::SSH#start. script
-
A string or array of commands
callback
-
(optional) A method to be called on each block of data received from the SSH execution. If none provided, we will simply use ‘puts`.
Examples:
ssh :localhost, ["cd /opt/app", "git pull"]
ssh { host: 'localhost', user: 'vagrant' }, "ls -l"
def my_puts(data, stream)
puts "> #{data}"
end
ssh :localhost, "ls -l", method: my_puts
34 35 36 |
# File 'lib/jossh/api.rb', line 34 def ssh(hostspec, script, callback: nil) CommandRunner.instance.ssh hostspec, script, callback: callback end |
#ssh!(hostspec, script) ⇒ Object
Same as ssh
, only this will print a pretty output.
This method accepts only hostspec
and script
(no callback
).
42 43 44 |
# File 'lib/jossh/api.rb', line 42 def ssh!(hostspec, script) CommandRunner.instance.ssh! hostspec, script end |
#ssh_hostfile(file) ⇒ Object
Set the name of the hostfile
Params:
file
-
Path to a YAML file
83 84 85 |
# File 'lib/jossh/api.rb', line 83 def ssh_hostfile(file) CommandRunner.instance.ssh_hostfile file end |
#ssh_script(hostspec, script, arguments: nil, callback: nil) ⇒ Object
Same as ssh
, only load commands from a file.
Params:
hostspec
-
See
ssh
script
-
A path to the script to run. The script file should be a file with a list of shell commands.
callback
-
(optional) See
ssh
Examples:
ssh_script :localhost, "deploy"
64 65 66 |
# File 'lib/jossh/api.rb', line 64 def ssh_script(hostspec, script, arguments: nil, callback: nil) CommandRunner.instance.ssh_script hostspec, script, arguments: arguments, callback: callback end |
#ssh_script!(hostspec, script, arguments: nil) ⇒ Object
Same as ssh_script
, only this will print a pretty output.
This method accepts only hostspec
and script
(no callback
).
72 73 74 |
# File 'lib/jossh/api.rb', line 72 def ssh_script!(hostspec, script, arguments: nil) CommandRunner.instance.ssh_script! hostspec, script, arguments: arguments end |