CORD-3169 Better catching of ansible failures
Change-Id: Ibd6f670410ac6a26a526b79ad99306ba481444e2
diff --git a/xos/synchronizers/new_base/ansible_helper.py b/xos/synchronizers/new_base/ansible_helper.py
index a1332cb..198047f 100644
--- a/xos/synchronizers/new_base/ansible_helper.py
+++ b/xos/synchronizers/new_base/ansible_helper.py
@@ -166,16 +166,16 @@
ofile.write('%s: %s\n'%(x._task, str(x._result)))
- if (object):
- oprops = object.tologdict()
- ansible = x._result
- oprops['xos_type']='ansible'
- oprops['ansible_result']=json.dumps(ansible)
+ if (object):
+ oprops = object.tologdict()
+ ansible = x._result
+ oprops['xos_type']='ansible'
+ oprops['ansible_result']=json.dumps(ansible)
if failed == 0:
- oprops['ansible_status']='OK'
+ oprops['ansible_status']='OK'
else:
- oprops['ansible_status']='FAILED'
+ oprops['ansible_status']='FAILED'
log.info('Ran Ansible task',task = x._task, **oprops)
@@ -185,10 +185,18 @@
if (expected_num is not None) and (len(ok_results) != expected_num):
raise ValueError('Unexpected num %s!=%d' % (str(expected_num), len(ok_results)) )
- #total_unreachable = stats.unreachable
+ if (failed):
+ raise ValueError('Ansible playbook failed.')
- if (failed):
- raise ValueError('Ansible playbook failed.')
+ # NOTE(smbaker): Playbook errors are slipping through where `aresults` does not show any failed tasks, but
+ # `stats` does show them. See CORD-3169.
+ hosts = sorted(stats.processed.keys())
+ for h in hosts:
+ t = stats.summarize(h)
+ if t['unreachable'] > 0:
+ raise ValueError("Ansible playbook reported unreachable for host %s" % h)
+ if t['failures'] > 0:
+ raise ValueError("Ansible playbook reported failures for host %s" % h)
except ValueError,e:
if error_msg:
diff --git a/xos/synchronizers/new_base/ansible_runner.py b/xos/synchronizers/new_base/ansible_runner.py
index 83eee03..5b02cf5 100644
--- a/xos/synchronizers/new_base/ansible_runner.py
+++ b/xos/synchronizers/new_base/ansible_runner.py
@@ -368,14 +368,6 @@
self.pbex.run()
stats = self.pbex._tqm._stats
- # Test if success for record_logs
- run_success = True
- hosts = sorted(stats.processed.keys())
- for h in hosts:
- t = stats.summarize(h)
- if t['unreachable'] > 0 or t['failures'] > 0:
- run_success = False
-
#os.remove(self.hosts.name)
return stats,callback.results