问题:
from fabric.api import *
env.hosts = ['10.46.220.251']
env.password = 'nasadmin'
def mytask(self):
run('uname -a')
mytask()
执行时,报错
No hosts found. Please specify (single) host string for connection:
debug:
Stack Overflow上找了答案
In order to get hosts to work in a script outside of the fab command-line tool and fabfile.py, you'll have to use execute():
from fabric.tasks import execute
def mytask():
run('uname -a')
results = execute(mytask)
fix:
def mytask(self):
run('uname -a')
results = execute(self.mytask)
转自:https://segmentfault.com/a/1190000012141881