Note that the reason you're getting the prompt up-front is because the :hosts key is evaluated at the time that the file is parsed. You can set the :hosts key to a Proc to force that evaluation to be deferred until the first time the task is actually executed:

set(:custom_username) { Capistrano::CLI.ui.ask("What is your ssh username: ") } task :deploy_to_dev, :hosts => Proc.new { "[EMAIL PROTECTED] " } do
    ...
  end

If you have multiple hosts, you just make the Proc return an array instead of a string. Likewise, the :roles value can be similarly deferred, if necessary.

Lastly, because Proc.new {...} looks kind of ungainly, Capistrano has an alias called "defer", to make it read more naturally:

task :deploy_to_dev, :hosts => defer { "[EMAIL PROTECTED] " } do
    ...
  end

The 'defer' alias can be used anywhere you would normally use Proc.new.

- Jamis

On Dec 13, 2007, at 2:31 PM, TravellingGuy wrote:


We're just getting into the world of capistrano to deploy websites.
Thanks to the excellent getting started docs at capify.org, I was able
to jump right in and create some fairly sophisticated deployment
scripts.

I'm using capistrano 2.1 and have no experience with previous
versions.

One thing that I would like to do is have cap ask for the username to
use when ssh'ing to the server to run tasks.  This would allow any of
our developers to deploy using their own login.  Note that the USER/
USERNAME environment variables won't work, because there's no
guarantee that the users remote login will be the same as their
username on their local machine.

I've tried this:
# Export from svn to test.gon.com
desc "Update dev environment from SVN"
task :deploy_to_dev, :hosts => "[EMAIL PROTECTED]" do
        ......do stuff
end

# Get user's ssh username
set(:ssh_username) do
        print "What is your ssh username? "
        STDOUT.flush
        STDIN.gets.chomp
end

However, doing a "cap --tasks" results in an error:
undefined local variable or method ssh_`username'

So, I moved the set(:ssh_username)....above the task:
# Get user's ssh username
set(:ssh_username) do
        print "What is your ssh username? "
        STDOUT.flush
        STDIN.gets.chomp
end

# Export from svn to test.gon.com
desc "Update dev environment from SVN"
task :deploy_to_dev, :hosts => "[EMAIL PROTECTED]" do
        ......do stuff
end

While this works, it has a side effect of asking for the users
username even when just doing a "cap --tasks".

Any ideas on other ways this could be accomplished?

Thanks

--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to