-
- 安装Fabric
pip install fabric #安装fabric
python –c “import fabric” #通过加载判断fabric是否安装正确
-
- fabfile.py
from fabric.api import run, sudo
from fabric.api import env
env.hosts= ['10.166.224.14', '10.166.224.14']
env.port= 2902
env.user='lmx'
def hostname():
run('hostname')
def ls(path='.'):
run('ls {}'.format(path))
def tail(path='/etc/passwd', line=10):
sudo('tail -n {0} {1}'.format(line, path))
fab –list
fab hostname
fab ls:/home
fab ls:path=/home
fab tail
fab tail:path=/etc/sudoers,line=3