Using an SSH keyfile with Fabric

Finding a simple fabfile with a working example of SSH keyfile usage isn’t easy for some reason. I wrote a blog post about it (with a matching gist). Basically, the usage goes something like this: from fabric.api import * env.hosts = [‘host.name.com’] env.user=”user” env.key_filename=”/path/to/keyfile.pem” def local_uname(): local(‘uname -a’) def remote_uname(): run(‘uname -a’) The important part … Read more

How to set target hosts in Fabric file

I do this by declaring an actual function for each environment. For example: def test(): env.user=”testuser” env.hosts = [‘test.server.com’] def prod(): env.user=”produser” env.hosts = [‘prod.server.com’] def deploy(): … Using the above functions, I would type the following to deploy to my test environment: fab test deploy …and the following to deploy to production: fab prod … Read more

Pass parameter to fabric task

Fabric 2 task arguments documentation: http://docs.pyinvoke.org/en/latest/concepts/invoking-tasks.html#task-command-line-arguments Fabric 1.X uses the following syntax for passing arguments to tasks: fab task:’hello world’ fab task:something=’hello’ fab task:foo=99,bar=True fab task:foo,bar You can read more about it in Fabric docs.

Activate a virtualenv via fabric as deploy user

As an update to bitprophet’s forecast: With Fabric 1.0 you can make use of prefix() and your own context managers. from __future__ import with_statement from fabric.api import * from contextlib import contextmanager as _contextmanager env.hosts = [‘servername’] env.user=”deploy” env.keyfile = [‘$HOME/.ssh/deploy_rsa’] env.directory = ‘/path/to/virtualenvs/project’ env.activate=”source /path/to/virtualenvs/project/bin/activate” @_contextmanager def virtualenv(): with cd(env.directory): with prefix(env.activate): yield def … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)