Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to deploy to 2 different server and these 2 servers have different authentication methods (one is my university's server and the other is an amazon web server AWS)

I already have running capistrano for my university's server, but I don't know how to add the deployment to AWS since for this one I need to add ssh options for example to user the .pem file, like this:

ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "test.pem")] 
ssh_options[:forward_agent] = true

I have browsed starckoverflow and no post mention about how to deal with different authentication methods this and this

I found a post that talks about 2 different keys, but this one refers to a server and a git, both usings different pem files. This is not the case.

I got to this tutorial, but couldn't find what I need.

I don't know if this is relevant for what I am asking: I am working on a rails app with ruby 1.9.2p290 and rails 3.0.10 and I am using an svn repository

Please any help os welcome. Thanks a lot

share|improve this question

2 Answers 2

This is best handled through ssh-configs rather than Capistrano directly. It's easier, anyway. The trick is aluded to in Paulo's answer on Stackoverflow. You'd build your ~/.ssh/config file to supply the needed parameters for the hosts you're looking for. Happily, this config file can accept wildcards which makes it easier to distinguish between AWS and Univ machines.

Host *.univ.edu
    IdentityFile ~/.ssh/id_rsa

Host [aws things]
    IdentityFIle ~/.ssh/aws.pem
    ForwardAgent Yes

The IdentityFile directive tells SSH which SSH key to use, which is how you tell it to select the right one depending on where you're going. The ForwardAgent is equivalent to the Capistrano directive you mentioned.

share|improve this answer

I do this exact thing using multistage from the capistrano-ext extension.

 gem install capistrano-ext

I have a few different stages created in config/deploy/ each with their own capistrano settings.

lunix@madeira]  (master) -> cat config/deploy/foo.rb 

set :user,   'ubuntu'
ssh_options[:keys] = File.expand_path('~/.ssh/awsfoo.pem')

server 'foo-01.example.com', :foo

.

lunix@madeira]  (master) -> cat config/deploy/bar.rb 

set :user,   'aussielunix'
ssh_options[:keys] = File.expand_path('~/.ssh/awsbar.pem')

server 'bar-01.example.org', :bar

Now it is a matter of just preceding the task with what stage you want to run the task against.

cap foo deploy
cap bar deploy
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.