Class: Sprinkle::Actors::SSH
Overview
The SSH actor requires no additional deployment tools other than the Ruby SSH libraries.
deployment do
delivery :ssh do
user "rails"
password "leetz"
port 2222
role :app, "app.myserver.com"
end
end
Use ssh key file
deployment do
delivery :ssh do
user "sprinkle"
keys "/path/to/ssh/key/file" # passed directly to Net::SSH as :keys option
role :app, "app.myserver.com"
end
end
Working thru a gateway
If you’re behind a firewall and need to use a SSH gateway that’s fine.
deployment do
delivery :ssh do
gateway "work.sshgateway.com"
end
end
Defined Under Namespace
Classes: SSHCommandFailure
Instance Attribute Summary collapse
-
#options ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#gateway(gateway) ⇒ Object
Set an optional SSH gateway server - if set all outbound SSH traffic will go thru this gateway.
-
#initialize(options = {}, &block) ⇒ SSH
constructor
:nodoc:.
-
#install(installer, roles, opts = {}) ⇒ Object
:nodoc:.
- #keys(keys) ⇒ Object
-
#password(password) ⇒ Object
Set the SSH password.
-
#port(port) ⇒ Object
Set the SSH port.
-
#role(role, server) ⇒ Object
Define a role and add servers to it role :app, “app.server.com” role :db, “db.server.com”.
-
#roles(roles) ⇒ Object
Define a whole host of roles at once.
-
#servers_for_role?(roles) ⇒ Boolean
Determines if there are any servers for the given roles.
-
#sudo? ⇒ Boolean
:nodoc:.
-
#sudo_command ⇒ Object
:nodoc:.
-
#teardown ⇒ Object
:nodoc:.
-
#use_sudo(value = true) ⇒ Object
Set this to true to prepend ‘sudo’ to every command.
-
#user(user) ⇒ Object
Set the SSH user.
-
#verify(verifier, roles) ⇒ Object
:nodoc:.
Constructor Details
#initialize(options = {}, &block) ⇒ SSH
:nodoc:
49 50 51 52 53 54 |
# File 'lib/sprinkle/actors/ssh.rb', line 49 def initialize( = {}, &block) #:nodoc: @options = .update(:user => 'root', :port => 22) @roles = {} self.instance_eval(&block) if block raise "You must define at least a single role." if @roles.empty? end |
Instance Attribute Details
Instance Method Details
#gateway(gateway) ⇒ Object
Set an optional SSH gateway server - if set all outbound SSH traffic will go thru this gateway
80 81 82 |
# File 'lib/sprinkle/actors/ssh.rb', line 80 def gateway(gateway) @options[:gateway] = gateway end |
#install(installer, roles, opts = {}) ⇒ Object
:nodoc:
128 129 130 131 132 133 134 135 |
# File 'lib/sprinkle/actors/ssh.rb', line 128 def install(installer, roles, opts = {}) #:nodoc: @installer = installer process(installer.package.name, installer.install_sequence, roles) rescue SSHCommandFailure => e raise_error(e) ensure @installer = nil end |
#keys(keys) ⇒ Object
99 100 101 |
# File 'lib/sprinkle/actors/ssh.rb', line 99 def keys(keys) @options[:keys] = keys end |
#password(password) ⇒ Object
Set the SSH password
90 91 92 |
# File 'lib/sprinkle/actors/ssh.rb', line 90 def password(password) @options[:password] = password end |
#port(port) ⇒ Object
Set the SSH port
95 96 97 |
# File 'lib/sprinkle/actors/ssh.rb', line 95 def port(port) @options[:port] = port end |
#role(role, server) ⇒ Object
Define a role and add servers to it
role :app, "app.server.com"
role :db, "db.server.com"
73 74 75 76 |
# File 'lib/sprinkle/actors/ssh.rb', line 73 def role(role, server) @roles[role] ||= [] @roles[role] << server end |
#roles(roles) ⇒ Object
Define a whole host of roles at once
This is depreciated - you should be using role instead.
59 60 61 |
# File 'lib/sprinkle/actors/ssh.rb', line 59 def roles(roles) #:nodoc: @roles = roles end |
#servers_for_role?(roles) ⇒ Boolean
Determines if there are any servers for the given roles
64 65 66 67 |
# File 'lib/sprinkle/actors/ssh.rb', line 64 def servers_for_role?(roles) #:nodoc: roles=Array(roles) roles.any? { |r| @roles.keys.include? (r) } end |
#sudo? ⇒ Boolean
:nodoc:
108 109 110 |
# File 'lib/sprinkle/actors/ssh.rb', line 108 def sudo? #:nodoc: @options[:use_sudo] end |
#sudo_command ⇒ Object
:nodoc:
112 113 114 |
# File 'lib/sprinkle/actors/ssh.rb', line 112 def sudo_command #:nodoc: "sudo" end |
#teardown ⇒ Object
:nodoc:
116 117 118 |
# File 'lib/sprinkle/actors/ssh.rb', line 116 def teardown #:nodoc: connections.shutdown! end |
#use_sudo(value = true) ⇒ Object
Set this to true to prepend ‘sudo’ to every command.
104 105 106 |
# File 'lib/sprinkle/actors/ssh.rb', line 104 def use_sudo(value=true) @options[:use_sudo] = value end |
#user(user) ⇒ Object
Set the SSH user
85 86 87 |
# File 'lib/sprinkle/actors/ssh.rb', line 85 def user(user) @options[:user] = user end |
#verify(verifier, roles) ⇒ Object
:nodoc:
120 121 122 123 124 125 126 |
# File 'lib/sprinkle/actors/ssh.rb', line 120 def verify(verifier, roles) #:nodoc: # issue all the verification steps in a single SSH command commands=[prepare_commands(verifier.commands).join(" && ")] process(verifier.package.name, commands, roles) rescue SSHCommandFailure false end |