1
我想遍历我的所有服务器配置织物,并得到他们的主机像这样:更新主机
from fabric.api import env, run
def serv_foo():
env.hosts = ['[email protected]']
def serv_bar():
env.hosts = ['[email protected]']
def get_all_servers():
return {(k,v) for k,v in globals().items() if k.startswith("serv_")}
def get_hostnames():
for serv_name, serv_fptr in get_all_servers():
print(env.hosts)
serv_fptr()
print(env.hosts)
hostname = run("hostname")
print(hostname)
然而,这失败:
>>> fab get_hostnames
>>> []
>>> ['[email protected]']
>>> No hosts found. Please specify (single) host string for connection:
如何动态更新织物中的主机?
- 注意1:我知道默认调用将是
fab serv_foo get_hostnames
。对此不感兴趣。 - 注2:
execute(serv_fptr)
给出同样的问题。
第一个答案像魅力一样运行。其次给出了相同的主机问题。随着第一个,也可以一般运行任何功能。谢谢。 – RickyA