From dbb1ec6488afb2d4388fa055b5489c74877a8b40 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Fri, 30 Dec 2011 13:28:48 -0500 Subject: [PATCH 1/2] Adding Fabric overview and example --- docs/scenarios/admin.rst | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index 1de9fa6..ed3c577 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -4,7 +4,41 @@ Systems Administration Fabric ------ -.. todo:: Write about Fabric +Fabric is a library for simplifying system administration tasks. While Chef +and Puppet tend to focus on managing servers and system libraries, +fabric is more focused on application level tasks such as deployment. + +Install Fabric: + +:: + + pip install fabric + +The following code will ssh into both of our servers, cd to our project +directory, activate the virtual environment, pull the newest codebase, +and restart the application server. + +:: + + from fabric.api import env, cd, run, prefix + + env.hosts = ['my_server1', 'my_server2'] + + def deploy(): + with cd('/var/www/project-env/project'): + with prefix('. ../bin/activate'): + run('git pull') + run('touch app.wsgi') + +With the previous code saved in a file named fabfile.py, we merely need to run +the following command to deploy our application to both of our servers. + +:: + + $ fab deploy + +Additional features include parallel execution, interaction with remote +programs, and host grouping. Chef ---- From 9a92f89919aad0681ee307e9364944c140f0871e Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Fri, 30 Dec 2011 14:25:41 -0500 Subject: [PATCH 2/2] Add task decorator to fabric example --- docs/scenarios/admin.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index ed3c577..84a9189 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -20,10 +20,11 @@ and restart the application server. :: - from fabric.api import env, cd, run, prefix + from fabric.api import cd, env, prefix, run, task env.hosts = ['my_server1', 'my_server2'] + @task def deploy(): with cd('/var/www/project-env/project'): with prefix('. ../bin/activate'):