DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Fabric Notes


Installation

  • sudo pip install fabric (verified on Mint 14, 2013-9-4)

  • sudo apt-get install fabric (verified on Ubuntu Server 12.04 with goagent, 2013-9-7)

Test "With" Statement of Fabric

When running fabric command on remote host, if the current directory after "with cd(...)" will return to original one? Let's test it.

fabfile.py

from __future__ import with_statement 
from fabric.api import local, settings, abort, run, cd 
def testcd(path): 
    run("pwd") 
    run("ls -l") 
    with cd(path): 
        run("pwd") 
        run("ls -l") 
    run("pwd") 
    run("ls -l")

Now run fab -H 10.0.7.142 -u gcp -p gcp@123 testcd:path="zdjk". The "pwd" and "ls" before and after "with" statement give the same result, which means "cd" in "with" statement only take effect in "with" block. It's cool.



Published

Sep 4, 2013

Last Updated

Sep 4, 2013

Category

Tech

Tags

  • fabric 8
  • Python 136

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor