Difference between revisions of "Fabric"

From air
Jump to navigation Jump to search
(Created page with "[http://www.fabfile.org/ Fabric] is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks...")
 
 
(3 intermediate revisions by the same user not shown)
Line 20: Line 20:
 
cd fabrictest
 
cd fabrictest
 
cat <<EOF > fabfile.py
 
cat <<EOF > fabfile.py
def hello():
+
def hello(name="world"):
print("Hello world!")
+
print("Hello %s!" % name)
 
EOF
 
EOF
 
fab --list
 
fab --list
 
fab hello
 
fab hello
  +
fab hello:name=Jeff
  +
fab hello:Jeff
  +
</pre>
   
  +
  +
  +
=Test Remote=
  +
<pre>
  +
cat <<EOF > fabfile.py
  +
from __future__ import with_statement
  +
from fabric.api import *
  +
# from fabric.contrib.console import confirm
  +
  +
env.hosts = ['host1', 'host2']
  +
  +
code_dir = '~/fabrictest'
  +
  +
@parallel
  +
def start():
  +
with cd(code_dir):
  +
run("./start.sh")
  +
  +
@parallel
  +
def stop():
  +
with cd(code_dir):
  +
run("./stop.sh")
  +
EOF
  +
  +
fab -i remotehost.pem start
 
</pre>
 
</pre>
  +
  +
  +
=Misc=
  +
* http://codefellows.github.io/python-dev-accelerator/assignments/day12/fabric.html

Latest revision as of 14:25, 4 August 2015

Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.


Install

sudo apt-get -y install python-pip
sudo apt-get -y install fabric
git clone https://github.com/warner/python-ecdsa.git
cd python-ecdsa/
sudo python setup.py install
cd ..
sudo rm -fr python-ecdsa
fab -V


Test

mkdir fabrictest
cd fabrictest
cat <<EOF > fabfile.py
def hello(name="world"):
    print("Hello %s!" % name)
EOF
fab --list
fab hello
fab hello:name=Jeff
fab hello:Jeff


Test Remote

cat <<EOF > fabfile.py
from __future__ import with_statement
from fabric.api import *
# from fabric.contrib.console import confirm

env.hosts = ['host1', 'host2']

code_dir = '~/fabrictest'

@parallel
def start():
    with cd(code_dir):
        run("./start.sh")

@parallel
def stop():
    with cd(code_dir):
        run("./stop.sh")
EOF

fab -i remotehost.pem start


Misc