diff --git a/tests/remote/test_remote_zuul_json.py b/tests/remote/test_remote_zuul_json.py index 11c03e207a..36c6b6bb61 100644 --- a/tests/remote/test_remote_zuul_json.py +++ b/tests/remote/test_remote_zuul_json.py @@ -81,6 +81,22 @@ class TestZuulJSON(AnsibleZuulTestCase): self.assertIn('rosebud', text) self.assertNotIn('setec', text) + def test_json_task_action(self): + job = self._run_job('no-log') + with self.jobLog(job): + build = self.history[-1] + self.assertEqual(build.result, 'SUCCESS') + + text = self._get_json_as_text(build) + json_result = json.loads(text) + tasks = json_result[0]['plays'][0]['tasks'] + expected_actions = [ + 'debug', 'debug', 'debug', 'copy', 'find', 'stat', 'debug' + ] + for i, expected in enumerate(expected_actions): + host_result = tasks[i]['hosts']['controller'] + self.assertEquals(expected, host_result['action']) + def test_json_role_log(self): job = self._run_job('json-role') with self.jobLog(job): diff --git a/zuul/ansible/callback/zuul_json.py b/zuul/ansible/callback/zuul_json.py index bbd2c24868..e52e2e24d1 100644 --- a/zuul/ansible/callback/zuul_json.py +++ b/zuul/ansible/callback/zuul_json.py @@ -132,6 +132,7 @@ class CallbackModule(CallbackBase): def v2_runner_on_ok(self, result, **kwargs): host = result._host + action = result._task.action if result._result.get('_ansible_no_log', False) or result._task.no_log: self.results[-1]['tasks'][-1]['hosts'][host.name] = dict( censored="the output has been hidden due to the fact that" @@ -155,6 +156,7 @@ class CallbackModule(CallbackBase): end_time = current_time() self.results[-1]['tasks'][-1]['task']['duration']['end'] = end_time self.results[-1]['play']['duration']['end'] = end_time + self.results[-1]['tasks'][-1]['hosts'][host.name]['action'] = action def v2_playbook_on_stats(self, stats): """Display info about playbook statistics"""