Skip to content

Commit 327fd09

Browse files
author
Kenneth Reitz
committed
Merge pull request realpython#54 from spulec/master
Adding Fabric overview and example
2 parents fcb5896 + 9a92f89 commit 327fd09

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

docs/scenarios/admin.rst

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,42 @@ Systems Administration
44
Fabric
55
------
66

7-
.. todo:: Write about Fabric
7+
Fabric is a library for simplifying system administration tasks. While Chef
8+
and Puppet tend to focus on managing servers and system libraries,
9+
fabric is more focused on application level tasks such as deployment.
10+
11+
Install Fabric:
12+
13+
::
14+
15+
pip install fabric
16+
17+
The following code will ssh into both of our servers, cd to our project
18+
directory, activate the virtual environment, pull the newest codebase,
19+
and restart the application server.
20+
21+
::
22+
23+
from fabric.api import cd, env, prefix, run, task
24+
25+
env.hosts = ['my_server1', 'my_server2']
26+
27+
@task
28+
def deploy():
29+
with cd('/var/www/project-env/project'):
30+
with prefix('. ../bin/activate'):
31+
run('git pull')
32+
run('touch app.wsgi')
33+
34+
With the previous code saved in a file named fabfile.py, we merely need to run
35+
the following command to deploy our application to both of our servers.
36+
37+
::
38+
39+
$ fab deploy
40+
41+
Additional features include parallel execution, interaction with remote
42+
programs, and host grouping.
843

944
Chef
1045
----

0 commit comments

Comments
 (0)