2014-10-05 52 views
0

我有我我的晶圆厂文件, 几台服务器,我想有一个会提示我做什么,不是所有的服务器上执行它的功能。蟒蛇面料的所有服务器上执行从迅速采取行动

def simple(): 
    actions = prompt('Type the actions: ') 
    run(actions) 

现在,当我这样做,我得到:

[web1] Type the actions: 
     bla bla bla 

[web2] Type the actions: 
     bla bla bla 

[web3] Type the actions: 
     bla bla bla 

我想键入“唧唧歪歪”只有一次,它会在所有服务器上执行, 这可能吗?

回答

0

那么,如果simple()这里是一个结构任务,那么就会出现这种行为,因为您将对执行该任务的每个主机调用prompt()。我想,你用fab命令行工具,并在最简单的情况:

# fabfile.py 

from fabric.api import run, env 

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

def simple(command=''): 
    run(command) 

,并按如下启动它:

$ fab simple:'ls -la' 
+0

感谢,但有可能做提示什么?因为我有很多“问题”,我希望它很容易被忽略 – 2014-10-05 13:02:56

+0

我不确定如果不修改'fab'工具的代码就可以直接执行此操作,但是您可以在shell脚本中轻松实现。这是一个bash单线程:'echo'输入操作:';阅读行动; fab fab simple:'$ actions'' – 2014-10-05 13:10:51

+0

ohhh好的,所以我会用你现在做的答案去... – 2014-10-05 13:19:07