Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6547 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

[PATCH] Allow multiple SSH ports to be specified along with the hostnames in capistrano deploy.rb files.

Reported by: ezmobius Assigned to: jamis@37signals.com
Priority: low Milestone: 1.x
Component: Capistrano Version: edge
Severity: normal Keywords: role gateway port username
Cc: jamis@37signals.com, bitsweat

Description

I was able to come up with a 3 line patch that allows for multiple ssh ports in capistrano deploy.rb files. All current tests still pass and backwards compatibility is completely retained. This patch allows for this syntax for defining roles as well as the old syntax and you can intermix the two and still use ssh_options[:port].

role :web, "65.74.169.199" role :app, "65.74.169.199:8029", "65.74.169.199:8030", "65.74.169.199:8031", "65.74.169.199:8032" role :prod_slave, "65.74.169.199:8030" role :db, "65.74.169.199", :primary => true

ssh_options[:port] = 8888

ssh_options[:port] will be over-ridden for any host that has :PORT as part of the string. And any IP's or hostnames that do not have :PORT in them will use the ssh_options[:port] num or 22 if this is not set.

Attachments

allow_multiple_ssh_ports_in_capistrano.diff (0.7 kB) - added by ezmobius on 11/05/06 07:16:42.
allow multiple ssh ports in capistyrano deploy.rb files
allow_multiple_ssh_ports_and_usernames_in_capistrano.diff (4.7 kB) - added by ezmobius on 11/06/06 06:33:08.
allow multiple ssh ports and usernames in capistyrano deploy.rb files
allow_multiple_ssh_ports_and_usernames_in_capistrano_with_gateways_too.diff (7.1 kB) - added by ezmobius on 11/08/06 01:46:54.
really_fix_capistrano_username_and_ports_patch.diff (1.6 kB) - added by ezmobius on 11/12/06 07:08:02.

Change History

11/05/06 07:16:42 changed by ezmobius

  • attachment allow_multiple_ssh_ports_in_capistrano.diff added.

allow multiple ssh ports in capistyrano deploy.rb files

11/05/06 07:19:20 changed by ezmobius

  • cc set to jamis@37signals.com.
  • owner changed from Tools to jamis@37signals.com.

11/05/06 18:38:21 changed by bitsweat

I'd love to see username@host:port also -

http://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04

(in reply to: ↑ description ) 11/06/06 06:15:47 changed by ezmobius

  • keywords deleted.

Ok I have rewritten the patch so it is not as ugly and I have implemented usernames in the server string as well. This passes all existing tests and is fully backwards compatible. And you can intermix the old way and the new way. Ports or usernames specified in the server address string take precedence over the global setting set elsewhere in the recipe file. I implemented the regex that matches according to the rfc for "user@hostname.com:8088". I considered allowing the password to be specified after the username with a : separating the two but decided against it because the rfc says it is frowned upon and not garaunteed to work. Here is the regex:

/(?:([;,:=]+)@|)(.*?)(?::(\d+)|)$/

The rfc says that the following characters are not allowed in a username: ; , : =

This patch also includes numerous new tests to assure correctness. I have used it a number of times today and it works great. I really hopre this makes it into capistrano so please let me know if there is anything else I can do to help it along. All of the changes are localized to the ssh.rb file so no other aspect of cap has been changed.

I am attaching the new patch.

11/06/06 06:33:08 changed by ezmobius

  • attachment allow_multiple_ssh_ports_and_usernames_in_capistrano.diff added.

allow multiple ssh ports and usernames in capistyrano deploy.rb files

11/07/06 18:38:50 changed by bitsweat

  • cc changed from jamis@37signals.com to jamis@37signals.com, bitsweat.
  • keywords set to role gateway port username.

Rockin!

11/07/06 19:17:23 changed by bitsweat

Doesn't work with gateways.

11/07/06 20:40:53 changed by ezmobius

crap. Ok I'll look into the gateway issue. Can you be any more specific? What didn't work with gateways? I don't ever use gateways but I will setup a test and see if I can fix it up for gateways as well.

11/08/06 01:46:40 changed by ezmobius

Ok I am attaching allow_multiple_ssh_ports_and_usernames_in_capistrano_with_gateways_too.diff. This one is the winner I think. I refactored the server string parsing into its own method so it can be used in both places. Added tests for the gateway and the server string parser.

Can you guys please test on your system to make sure Gateway works fine for you. Gateway and everything else is working fine for me now.

11/08/06 01:46:54 changed by ezmobius

  • attachment allow_multiple_ssh_ports_and_usernames_in_capistrano_with_gateways_too.diff added.

11/11/06 00:57:17 changed by bitsweat

Working great for me.

11/11/06 04:21:56 changed by minam

  • status changed from new to closed.
  • resolution set to fixed.

(In [5483]) Allow SSH user and port to be encoded in the hostname strings (excellent job, Ezra!) closes #6547

11/12/06 07:07:41 changed by ezmobius

  • status changed from closed to reopened.
  • resolution deleted.

I actually just discovered a very tiny bug that happened when I pulled up the server_parse into its own method. I was overwriting the server string instead of just parsing it because I re-used the server variable. Anyway I have fixed it and I have a tiny patch for you here to finish this thing up proper.

Subtle bug but I ran into it when intermixing all the different styles of hostnames. This patch should make it never overwrite the server string which means that the parse will always work instead of stripping off a username or port.

Sorry I didn't catch this before you committed it Jamis. This should be applied as soon as you get a chance.

11/12/06 07:08:02 changed by ezmobius

  • attachment really_fix_capistrano_username_and_ports_patch.diff added.

12/09/06 04:21:47 changed by minam

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [5708]) fix problem with overwriting server name (closes #6547)

04/17/07 19:08:49 changed by phil76

  • priority changed from high to low.
  • status changed from closed to reopened.
  • resolution deleted.
  • type changed from enhancement to defect.

i have the following in my deploy.rb:

role :app, "my.server.com:15241" role :app, "my.server.com:15242"

#set :gateway, "some.gateway.com" # default to no gateway

ssh_options[:port] = 2222

only when i comment out the ssh_options[:port] part, capistrano successfully connects to the app servers; i get a ETIMEDOUT if i leave it in). if i understand the ticket description correctly, the intended behavior would be he port given in the role config _should_ be used even if ssh_options[:port] is set? currently the other way around, as ssh_options[:port] is merged over the options parsed out from the hostname (ssh.rb line 31).

(i am running version 1.4.1)

cheers, phillip

04/17/07 19:10:53 changed by phil76

(sorry if i changed too many of the ticket properties; and the spelling errors ...)

06/14/07 16:01:50 changed by minam

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [7024]) server options take precedence over ssh_options (closes #6547)