01 June 2015

info

  1. fabric is a python (2.5-2.7) library and command-line tool

  2. for streamlining the use of ssh

    • for application deployment

    • for system administration tasks

installing

  1. pip

         $ pip install fabric
    
  2. via os’s package manager, package called fabric or python-fabric

         $ sudo apt-get install fabric
    
  3. via conda

         $ conda install fabric
    

demo

  1. hello world

    1. fabfile.py

       $ pico fabfile.py
       def hello_world():
           print 'hello world'
      
    2. run

       $ fab hello_world
       hello world
      
       Done.
      
  2. hello world with parameter

    1. fabfile.py

       $ pico fabfile.py
       def hello_world(username):
           print 'hello world {}'.format(username)
      
    2. run

       $ fab hello_world:hqlgree2
       hello world hqlgree2
      
       Done.
      
  3. uname -s

    1. fabfile.py

       $ pico fabfile.py
       from fabric.api import run
      
       def host_type():
           run('uname -s')
      
    2. run

       $ fab host_type
       No hosts found. Please specify (single) host string for connection: localhost
       [localhost] run: uname -s
       [localhost] out: Darwin
       [localhost] out: 
      
      
       Done.
       Disconnecting from localhost... done.
      
       $ fab host_type -H localhost,linuxbox
      


blog comments powered by Disqus