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