From d3f3784b86789b7b55782b0af4fba6d6bb935f19 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Fri, 5 Feb 2021 09:06:19 -0600 Subject: [PATCH] Don't treat host_pinned as lockstep (#73484) * Don't treat host_pinned as lockstep. Fixes #73364 * Add intg tests --- ...ault-callback-host-pinned-not-lockstep.yml | 3 ++ lib/ansible/plugins/callback/default.py | 4 +-- .../callback_default.out.free.stdout | 29 +++++++++++++++++++ .../callback_default.out.host_pinned.stdout | 29 +++++++++++++++++++ .../targets/callback_default/inventory | 5 ++++ .../targets/callback_default/runme.sh | 4 +++ .../callback_default/test_non_lockstep.yml | 7 +++++ 7 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/73364-default-callback-host-pinned-not-lockstep.yml create mode 100644 test/integration/targets/callback_default/callback_default.out.free.stdout create mode 100644 test/integration/targets/callback_default/callback_default.out.host_pinned.stdout create mode 100644 test/integration/targets/callback_default/test_non_lockstep.yml diff --git a/changelogs/fragments/73364-default-callback-host-pinned-not-lockstep.yml b/changelogs/fragments/73364-default-callback-host-pinned-not-lockstep.yml new file mode 100644 index 00000000000..bcfa35f1c17 --- /dev/null +++ b/changelogs/fragments/73364-default-callback-host-pinned-not-lockstep.yml @@ -0,0 +1,3 @@ +bugfixes: +- default callback - Ensure that the ``host_pinned`` strategy is not treated as lockstep + (https://github.com/ansible/ansible/issues/73364) diff --git a/lib/ansible/plugins/callback/default.py b/lib/ansible/plugins/callback/default.py index 7872974d4f3..9087aacdf2d 100644 --- a/lib/ansible/plugins/callback/default.py +++ b/lib/ansible/plugins/callback/default.py @@ -188,8 +188,8 @@ class CallbackModule(CallbackBase): # Preserve task name, as all vars may not be available for templating # when we need it later - if self._play.strategy == 'free': - # Explicitly set to None for strategy 'free' to account for any cached + if self._play.strategy in ('free', 'host_pinned'): + # Explicitly set to None for strategy free/host_pinned to account for any cached # task title from a previous non-free play self._last_task_name = None else: diff --git a/test/integration/targets/callback_default/callback_default.out.free.stdout b/test/integration/targets/callback_default/callback_default.out.free.stdout new file mode 100644 index 00000000000..1c743fb6737 --- /dev/null +++ b/test/integration/targets/callback_default/callback_default.out.free.stdout @@ -0,0 +1,29 @@ + +PLAY [nonlockstep] ************************************************************* + +TASK [command] ***************************************************************** +changed: [testhost10] +changed: [testhost11] + +TASK [command] ***************************************************************** +changed: [testhost10] + +TASK [command] ***************************************************************** +changed: [testhost12] + +TASK [command] ***************************************************************** +changed: [testhost10] + +TASK [command] ***************************************************************** +changed: [testhost11] +changed: [testhost12] + +TASK [command] ***************************************************************** +changed: [testhost11] +changed: [testhost12] + +PLAY RECAP ********************************************************************* +testhost10 : ok=3 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 +testhost11 : ok=3 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 +testhost12 : ok=3 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + diff --git a/test/integration/targets/callback_default/callback_default.out.host_pinned.stdout b/test/integration/targets/callback_default/callback_default.out.host_pinned.stdout new file mode 100644 index 00000000000..1c743fb6737 --- /dev/null +++ b/test/integration/targets/callback_default/callback_default.out.host_pinned.stdout @@ -0,0 +1,29 @@ + +PLAY [nonlockstep] ************************************************************* + +TASK [command] ***************************************************************** +changed: [testhost10] +changed: [testhost11] + +TASK [command] ***************************************************************** +changed: [testhost10] + +TASK [command] ***************************************************************** +changed: [testhost12] + +TASK [command] ***************************************************************** +changed: [testhost10] + +TASK [command] ***************************************************************** +changed: [testhost11] +changed: [testhost12] + +TASK [command] ***************************************************************** +changed: [testhost11] +changed: [testhost12] + +PLAY RECAP ********************************************************************* +testhost10 : ok=3 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 +testhost11 : ok=3 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 +testhost12 : ok=3 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + diff --git a/test/integration/targets/callback_default/inventory b/test/integration/targets/callback_default/inventory index e75c585dc0f..9236403493e 100644 --- a/test/integration/targets/callback_default/inventory +++ b/test/integration/targets/callback_default/inventory @@ -3,3 +3,8 @@ testhost ansible_connection=local ansible_python_interpreter="{{ ansible_playboo [nonexistent] testhost5 ansible_host=169.254.199.200 # no connection is ever established with this host + +[nonlockstep] +testhost10 i=1.0 ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}" +testhost11 i=2.0 ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}" +testhost12 i=3.0 ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}" diff --git a/test/integration/targets/callback_default/runme.sh b/test/integration/targets/callback_default/runme.sh index d18a2293c75..537abfd94e7 100755 --- a/test/integration/targets/callback_default/runme.sh +++ b/test/integration/targets/callback_default/runme.sh @@ -192,3 +192,7 @@ ansible-playbook -i host1,host2 no_implicit_meta_banners.yml > meta_test.out cat meta_test.out [ "$(grep -c 'TASK \[meta\]' meta_test.out)" -eq 0 ] rm -f meta_test.out + +# Ensure free/host_pinned non-lockstep strategies display correctly +diff -u <(ANSIBLE_STRATEGY=free ansible-playbook -i inventory test_non_lockstep.yml 2>/dev/null) callback_default.out.free.stdout +diff -u <(ANSIBLE_STRATEGY=host_pinned ansible-playbook -i inventory test_non_lockstep.yml 2>/dev/null) callback_default.out.host_pinned.stdout diff --git a/test/integration/targets/callback_default/test_non_lockstep.yml b/test/integration/targets/callback_default/test_non_lockstep.yml new file mode 100644 index 00000000000..8a05029be14 --- /dev/null +++ b/test/integration/targets/callback_default/test_non_lockstep.yml @@ -0,0 +1,7 @@ +--- +- hosts: nonlockstep + gather_facts: false + tasks: + - command: sleep {{ 2 * i }} + - command: sleep {{ 2 * i }} + - command: sleep {{ 2 * i }}