title: webistrano ssh-agent
body: <p>I have a Webistrano setup that deploys with its own private/public key pair. I would like to harness the simplicity of <code>:remote_cache</code> strategy, but don't want to copy the private key to the deployment server.</p>
  
  <p>So long I have these tasks set up:</p>
  
  <pre><code>namespace :ssh do 
    task :start_agent do 
      ssh_options[:forward_agent] = true
      result = `ssh-agent -t 600`
      # Extract env variables
      %w(SSH_AUTH_SOCK SSH_AGENT_PID).each do |key|
        if result =~ /#{key}=(.*?);/
            ENV[key] = $1
        end
      end
      cmd = "ssh-add #{ssh_keys}"
      result = `cmd`
    end 
  
    task :stop_agent do
      # Kill the agent started previously
      `ssh_agent -k $SSH_AGENT_PID`
    end
  end 
  
  before 'deploy', 'ssh:start_agent'
  </code></pre>
  
  <p>This <code>before :deploy</code> seems to work half way, but I have few problems:</p>
  
  <ol>
  <li>I need to stop the agent after deploy (and after failed deploy). Is there any callback I can hook the <code>ssh:stop_agent</code> task?</li>
  <li>The <code>deploy:update_code</code> task fails with error <em>Unable to resolve revision for 'master' on repository 'git@git.eenet.ee:base/mms.git'</em></li>
  </ol>
  
  <p>Can anybody shed any light on this?</p>