[英]How to get failed hosts in fabric
I am using fabric and have a lot of hosts I have to process. 我正在使用结构,并且有很多主机需要处理。
If any hosts fails I continue with execution with: 如果任何主机发生故障,我将继续执行以下操作:
env.warn_only = True
However I want to get a list of hosts at the end that failed. 但是,我想在失败的末尾获得主机列表。 How? 怎么样? I tried the below and I get nothing for either a success or fail. 我尝试了以下内容,但无论成功还是失败,我一无所获。
error_list= []
success_list = []
@parallel
def my_run():
try:
sudo('sh test.sh')
success_list.append(env.host)
except:
error_this.append(env.host)
error_list= []
success_list = []
Here is a code I use: 这是我使用的代码:
@parallel
@roles(env.roles)
def dummy_workhorse():
return run('hostname')
@task
@runs_once
@with_settings(hide('everything'), skip_bad_hosts=True)
@needs_host
def check_hosts():
down_hosts = []
for host, result in execute(dummy_workhorse).iteritems():
if not isinstance(result, str):
down_hosts.append(host)
if down_hosts:
print('Following hosts are down:')
for host in down_hosts:
print(host)
else:
print('All hosts are up and running!')
Try using 'env.host_string' instead of 'env.host' Ref: http://docs.fabfile.org/en/1.8/usage/env.html#host-string 尝试使用“ env.host_string”而不是“ env.host”参考: http : //docs.fabfile.org/en/1.8/usage/env.html#host-string
error_list= []
success_list = []
@parallel
def my_run():
try:
sudo('sh test.sh')
success_list.append(env.host_string)
except:
error_list.append(env.host_string)
error_list= []
success_list = []
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.