diff --git a/zuul/ansible/callback/zuul_json.py b/zuul/ansible/callback/zuul_json.py index fa96f771ac..612a720697 100644 --- a/zuul/ansible/callback/zuul_json.py +++ b/zuul/ansible/callback/zuul_json.py @@ -24,7 +24,6 @@ __metaclass__ = type import json import os -import re from ansible.plugins.callback import CallbackBase try: @@ -59,7 +58,6 @@ class CallbackModule(CallbackBase): # Get the hostvars from just one host - the vars we're looking for will # be identical on all of them hostvars = next(iter(play._variable_manager._hostvars.values())) - playbook = self._playbook_name self._playbook_name = None # TODO(mordred) For now, protect specific variable lookups to make it @@ -68,24 +66,16 @@ class CallbackModule(CallbackBase): # tool. phase = hostvars.get('zuul_execution_phase') index = hostvars.get('zuul_execution_phase_index') - - # imply work_dir from src_root - src_root = hostvars.get('zuul', {}).get('executor', {}).get('src_root') - if src_root: - # Ensure work_dir has a trailing / for ease of stripping - work_dir = os.path.dirname( - os.path.dirname(src_root)).rstrip('/') + '/' - # Strip work_dir from the beginning of the playbook name. - playbook = playbook.replace(work_dir, '') - - # Lop off the first two path elements - ansible/pre_playbook_0 - playbook = re.sub('(un)?trusted/project_[^/]+/', '', playbook) - # Remove yaml suffix - playbook = os.path.splitext(playbook)[0] + playbook = hostvars.get('zuul_execution_canonical_name_and_path') + trusted = hostvars.get('zuul_execution_trusted') + trusted = True if trusted == "True" else False + branch = hostvars.get('zuul_execution_branch') self.playbook['playbook'] = playbook self.playbook['phase'] = phase self.playbook['index'] = index + self.playbook['trusted'] = trusted + self.playbook['branch'] = branch def _new_play(self, play): return { diff --git a/zuul/ansible/callback/zuul_stream.py b/zuul/ansible/callback/zuul_stream.py index 171b25c88d..69bc2bb9ae 100644 --- a/zuul/ansible/callback/zuul_stream.py +++ b/zuul/ansible/callback/zuul_stream.py @@ -23,7 +23,6 @@ import datetime import logging import json import os -import re import socket import threading import time @@ -165,34 +164,20 @@ class CallbackModule(default.CallbackModule): # Get the hostvars from just one host - the vars we're looking for will # be identical on all of them hostvars = next(iter(self._play._variable_manager._hostvars.values())) - playbook = self._playbook_name self._playbook_name = None - # TODO(mordred) For now, protect specific variable lookups to make it - # not absurdly strange to run local tests with the callback plugin - # enabled. Remove once we have a "run playbook like zuul runs playbook" - # tool. - phase = hostvars.get('zuul_execution_phase') + phase = hostvars.get('zuul_execution_phase', '') + playbook = hostvars.get('zuul_execution_canonical_name_and_path') + trusted = hostvars.get('zuul_execution_trusted') + trusted = 'trusted' if trusted == "True" else 'untrusted' + branch = hostvars.get('zuul_execution_branch') + if phase and phase != 'run': phase = '{phase}-run'.format(phase=phase) phase = phase.upper() - # imply work_dir from src_root - src_root = hostvars.get('zuul', {}).get('executor', {}).get('src_root') - if src_root: - # Ensure work_dir has a trailing / for ease of stripping - work_dir = os.path.dirname( - os.path.dirname(src_root)).rstrip('/') + '/' - # Strip work_dir from the beginning of the playbook name. - playbook = playbook.replace(work_dir, '') - - # Lop off the first two path elements - ansible/pre_playbook_0 - playbook = re.sub('(un)?trusted/project_[^/]+/', '', playbook) - # Remove yaml suffix - playbook = os.path.splitext(playbook)[0] - - self._log("{phase} [{playbook}]".format( - phase=phase, playbook=playbook)) + self._log("{phase} [{trusted} : {playbook}@{branch}]".format( + trusted=trusted, phase=phase, playbook=playbook, branch=branch)) def v2_playbook_on_play_start(self, play): self._play = play diff --git a/zuul/executor/server.py b/zuul/executor/server.py index 93bb92d640..6e4b15cc4b 100644 --- a/zuul/executor/server.py +++ b/zuul/executor/server.py @@ -1423,6 +1423,13 @@ class AnsibleJob(object): if index is not None: cmd.extend(['-e', 'zuul_execution_phase_index=%s' % index]) + cmd.extend(['-e', 'zuul_execution_trusted=%s' % str(playbook.trusted)]) + cmd.extend([ + '-e', + 'zuul_execution_canonical_name_and_path=%s' + % playbook.canonical_name_and_path]) + cmd.extend(['-e', 'zuul_execution_branch=%s' % str(playbook.branch)]) + result, code = self.runAnsible( cmd=cmd, timeout=timeout, config_file=playbook.ansible_config,