diff --git a/ansible_runner/display_callback/callback/awx_display.py b/ansible_runner/display_callback/callback/awx_display.py index 0388a9a94..aa29f39db 100644 --- a/ansible_runner/display_callback/callback/awx_display.py +++ b/ansible_runner/display_callback/callback/awx_display.py @@ -554,6 +554,7 @@ def v2_playbook_on_task_start(self, task, is_conditional): name=task.get_name(), is_conditional=is_conditional, uuid=task_uuid, + resolved_action=getattr(task, 'resolved_action', '') ) with self.capture_event_data('playbook_on_task_start', **event_data): super(CallbackModule, self).v2_playbook_on_task_start(task, is_conditional) diff --git a/requirements.txt b/requirements.txt index 99995ce35..09cf067a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ pexpect>=4.5 +packaging python-daemon pyyaml six diff --git a/test/conftest.py b/test/conftest.py index 5e786f408..558dc24b3 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,6 +1,8 @@ import shutil from pathlib import Path +from packaging.version import Version +import subprocess from ansible_runner import defaults @@ -46,6 +48,30 @@ def skipif_pre_ansible211(is_pre_ansible211): pytest.skip("Valid only on Ansible 2.11+") +@pytest.fixture(scope="session") +def is_pre_ansible212(): + try: + base_version = ( + subprocess.run( + "python -c 'import ansible; print(ansible.__version__)'", + capture_output=True, + shell=True, + ) + .stdout.strip() + .decode() + ) + if Version(base_version) < Version("2.12"): + return True + except pkg_resources.DistributionNotFound: + pass + + +@pytest.fixture(scope="session") +def skipif_pre_ansible212(is_pre_ansible212): + if is_pre_ansible212: + pytest.skip("Valid only on Ansible 2.12+") + + # TODO: determine if we want to add docker / podman # to zuul instances in order to run these tests def pytest_generate_tests(metafunc): diff --git a/test/integration/test_display_callback.py b/test/integration/test_display_callback.py index 24bc9075f..5d05d71fc 100644 --- a/test/integration/test_display_callback.py +++ b/test/integration/test_display_callback.py @@ -198,7 +198,32 @@ def test_callback_plugin_task_args_leak(executor, playbook): assert not events[-1]['event_data']['failures'], 'Unexpected playbook execution failure' -@pytest.mark.parametrize('playbook', [ +@pytest.mark.parametrize( + "playbook", + [ + { + "simple.yml": """ +- name: simpletask + connection: local + hosts: all + gather_facts: no + tasks: + - shell: echo "resolved actions test!" +""" + }, # noqa + ], +) +def test_resolved_actions(executor, playbook, skipif_pre_ansible212): + executor.run() + events = list(executor.events) + + # task 1 + assert events[2]["event"] == "playbook_on_task_start" + assert "resolved_action" in events[2]["event_data"] + assert events[2]["event_data"]["resolved_action"] == "ansible.builtin.shell" + + +@pytest.mark.parametrize("playbook", [ {'loop_with_no_log.yml': ''' - name: playbook variable should not be overwritten when using no log connection: local