Add phase and count to variables passed in to playbooks

It would be nice to be able to show pre, run and post output separately,
but we need to know which of these things is happening so that the log
output can mark things appropriately. Pass in values so that zuul_stream
and friends can do something with them.

Change-Id: Iedb4f8504ce13dd8725685b6ef0bb3763675c218
This commit is contained in:
Monty Taylor 2017-07-09 09:56:21 -05:00
parent 37338d33bf
commit e0d232398d
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
1 changed files with 13 additions and 6 deletions

View File

@ -883,10 +883,10 @@ class AnsibleJob(object):
result = None
pre_failed = False
for playbook in self.jobdir.pre_playbooks:
for count, playbook in enumerate(self.jobdir.pre_playbooks):
# TODOv3(pabelanger): Implement pre-run timeout setting.
pre_status, pre_code = self.runAnsiblePlaybook(
playbook, args['timeout'])
playbook, args['timeout'], phase='pre', count=count)
if pre_status != self.RESULT_NORMAL or pre_code != 0:
# These should really never fail, so return None and have
# zuul try again
@ -896,7 +896,7 @@ class AnsibleJob(object):
if not pre_failed:
job_status, job_code = self.runAnsiblePlaybook(
self.jobdir.playbook, args['timeout'])
self.jobdir.playbook, args['timeout'], phase='run')
if job_status == self.RESULT_TIMED_OUT:
return 'TIMED_OUT'
if job_status == self.RESULT_ABORTED:
@ -912,10 +912,10 @@ class AnsibleJob(object):
else:
result = 'FAILURE'
for playbook in self.jobdir.post_playbooks:
for count, playbook in enumerate(self.jobdir.post_playbooks):
# TODOv3(pabelanger): Implement post-run timeout setting.
post_status, post_code = self.runAnsiblePlaybook(
playbook, args['timeout'], success)
playbook, args['timeout'], success, phase='post', count=count)
if post_status != self.RESULT_NORMAL or post_code != 0:
# If we encountered a pre-failure, that takes
# precedence over the post result.
@ -1370,7 +1370,8 @@ class AnsibleJob(object):
return (self.RESULT_NORMAL, ret)
def runAnsiblePlaybook(self, playbook, timeout, success=None):
def runAnsiblePlaybook(self, playbook, timeout, success=None,
phase=None, count=None):
env_copy = os.environ.copy()
env_copy['LOGNAME'] = 'zuul'
@ -1384,6 +1385,12 @@ class AnsibleJob(object):
if success is not None:
cmd.extend(['-e', 'success=%s' % str(bool(success))])
if phase:
cmd.extend(['-e', 'zuul_execution_phase=%s' % phase])
if count is not None:
cmd.extend(['-e', 'zuul_execution_phase_count=%s' % count])
result, code = self.runAnsible(
cmd=cmd, timeout=timeout, trusted=playbook.trusted)
self.log.debug("Ansible complete, result %s code %s" % (