diff --git a/changelogs/fragments/end_host-remove_host_from_play.yml b/changelogs/fragments/end_host-remove_host_from_play.yml new file mode 100644 index 00000000000..dc77a0bab03 --- /dev/null +++ b/changelogs/fragments/end_host-remove_host_from_play.yml @@ -0,0 +1,2 @@ +bugfixes: + - "Fix a bug when a host was not removed from a play after ``meta: end_host`` and as a result the host was still present in ``ansible_play_hosts`` and ``ansible_play_batch`` variables." diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index dc83744a12e..03edd50667c 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -1094,6 +1094,7 @@ class StrategyBase: elif meta_action == 'end_host': if _evaluate_conditional(target_host): iterator._host_states[target_host.name].run_state = iterator.ITERATING_COMPLETE + iterator._play._removed_hosts.append(target_host.name) msg = "ending play for %s" % target_host.name else: skipped = True