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
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 = []
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.