Using Fabric to update a remote svn checkout with ssh public key authentication

jul 14, 2009 - Remco - publickey - deployment - python - fabric - django - ssh - Development

For our subversion repositories we only allow users to connect through ssh public key login. We are switching towards using Fabric for doing automated deployments (in combination with zc.buildout, which we already use).

Unfortunately it seems that both Fabric and paramiko, the python library Fabric uses for making ssh connections, don't support the ForwardAgent option in ~/.ssh/config which allows you to forward your ssh-agent to a remote machine and from there connect to other machines using your public key.

A workaround for this is relatively simple though. Instead of using run() to perform the svn update remotely through Fabric and Paramiko, you can use the local() command to initiate an ssh connection using your local system's ssh command:

from fabric.api import *

def staging():
    env.hosts = ['my_server.example.org']
    env.project_root = '[/srv/my_project]'

def deploy():
    "Deploy code to servers"
    require('hosts', provided_by = [staging])

    local('ssh %s "svn up %s"' % (env.host, env.project_root))

This will do an svn update on the checkout in /srv/my_project on the host my_server.example.org.



Austria x 1, Ukraine x 2, United Kingdom x 2, Uruguay x 1, Belgium x 1, Romania x 1, Switzerland x 1, Luxembourg x 1, Sweden x 1, Netherlands x 4, Germany x 1, Brazil x 1

If you found this post useful, funny or whatever, let us know without writing a full comment!

comments powered by Disqus

Latest Tweets