diff --git a/zuul/ansible/callback/zuul_stream.py b/zuul/ansible/callback/zuul_stream.py index d794ce7809..c4473da067 100644 --- a/zuul/ansible/callback/zuul_stream.py +++ b/zuul/ansible/callback/zuul_stream.py @@ -150,14 +150,29 @@ class CallbackModule(default.CallbackModule): def v2_playbook_on_start(self, playbook): self._playbook_name = os.path.splitext(playbook._file_name)[0] + def v2_playbook_on_include(self, included_file): + for host in included_file._hosts: + self._log("{host} | included: {filename}".format( + host=host.name, + filename=included_file._filename)) + def v2_playbook_on_play_start(self, play): self._play = play + # Get the hostvars from just one host - the vars we're looking for will + # be identical on all of them + hostvars = self._play._variable_manager._hostvars + a_host = hostvars.keys()[0] + self.phase = hostvars[a_host]['zuul_execution_phase'] + if self.phase != 'run': + self.phase = '{phase}-{index}'.format( + phase=self.phase, + index=hostvars[a_host]['zuul_execution_phase_index']) + + # the name of a play defaults to the hosts string name = play.get_name().strip() - if not name: - msg = u"PLAY" - else: - msg = u"PLAY [{playbook} : {name}]".format( - playbook=self._playbook_name, name=name) + msg = u"PLAY [{phase} : {playbook} : {name}]".format( + phase=self.phase, + playbook=self._playbook_name, name=name) self._log(msg) # Log an extra blank line to get space after each play diff --git a/zuul/executor/server.py b/zuul/executor/server.py index bc30386d18..3530f393e2 100644 --- a/zuul/executor/server.py +++ b/zuul/executor/server.py @@ -883,10 +883,10 @@ class AnsibleJob(object): result = None pre_failed = False - for count, playbook in enumerate(self.jobdir.pre_playbooks): + for index, playbook in enumerate(self.jobdir.pre_playbooks): # TODOv3(pabelanger): Implement pre-run timeout setting. pre_status, pre_code = self.runAnsiblePlaybook( - playbook, args['timeout'], phase='pre', count=count) + playbook, args['timeout'], phase='pre', index=index) if pre_status != self.RESULT_NORMAL or pre_code != 0: # These should really never fail, so return None and have # zuul try again @@ -912,10 +912,10 @@ class AnsibleJob(object): else: result = 'FAILURE' - for count, playbook in enumerate(self.jobdir.post_playbooks): + for index, playbook in enumerate(self.jobdir.post_playbooks): # TODOv3(pabelanger): Implement post-run timeout setting. post_status, post_code = self.runAnsiblePlaybook( - playbook, args['timeout'], success, phase='post', count=count) + playbook, args['timeout'], success, phase='post', index=index) if post_status != self.RESULT_NORMAL or post_code != 0: # If we encountered a pre-failure, that takes # precedence over the post result. @@ -1373,7 +1373,7 @@ class AnsibleJob(object): return (self.RESULT_NORMAL, ret) def runAnsiblePlaybook(self, playbook, timeout, success=None, - phase=None, count=None): + phase=None, index=None): env_copy = os.environ.copy() env_copy['LOGNAME'] = 'zuul' @@ -1390,8 +1390,8 @@ class AnsibleJob(object): if phase: cmd.extend(['-e', 'zuul_execution_phase=%s' % phase]) - if count is not None: - cmd.extend(['-e', 'zuul_execution_phase_count=%s' % count]) + if index is not None: + cmd.extend(['-e', 'zuul_execution_phase_index=%s' % index]) result, code = self.runAnsible( cmd=cmd, timeout=timeout, trusted=playbook.trusted)