Help with meta end_host

Hi,

I have a playbook that uses a meta task to end the play for hosts not meeting a certain condition. Further along the playbook I have a run_once task that uses the ansible_play_hosts variable to provide a list of the hosts in the current play to a command.

My issue is that although I end the play for the hosts not meeting the required condition, they persist in the ansible_play_hosts variable - I guess this is expected since they are not failed and therefore still technically part of the play even though they will not have any further tasks executed against them. Is there any way of getting or creating a list of the hosts that remain active for the remaining tasks?

Here is a test playbook demonstrating that the play has ended for a particular host but remains in the play_hosts variable;

------ test_meta.yml ---------

I could just confirm such behavior, seems it’s a bug in meta: end_host, what such action does not update ansible_play_hosts ( and ansible_play_batch ).
And in the Ansible 2.9.2 version it’s still the same behavior.

As the workaround you could try meta: fail, but it’s not so nice and could have side effects, if you’re relying on the play’s exist state for example.

Anyway, you could try to construct similar logic by yourself with set_fact: and when: actions.

Hello,

I have opened a pull request that should fix the issue at
https://github.com/ansible/ansible/pull/66851.

Thanks!
Martin