# Help with meta end\_host

**URL:** <https://forum.ansible.com/t/help-with-meta-end-host/31324>\
**Category:** Ansible Project\
**Created:** [September 20, 2019, 2:38pm UTC](https://forum.ansible.com/t/help-with-meta-end-host/31324 "2019-09-20T14:38:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KSS](https://avatars.discourse-cdn.com/v4/letter/k/a587f6/32.png) [@KSS](https://forum.ansible.com/u/KSS)\
**Post date:** [September 20, 2019, 2:38pm UTC](https://forum.ansible.com/t/help-with-meta-end-host/31324/1 "2019-09-20T14:38:31Z")

</div>

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 ---------

---

<div class="post-metadata">

**Author:** ![Aleksandr\_Smirnov](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@Aleksandr\_Smirnov](https://forum.ansible.com/u/Aleksandr_Smirnov)\
**Post date:** [January 28, 2020, 11:59am UTC](https://forum.ansible.com/t/help-with-meta-end-host/31324/2 "2020-01-28T11:59:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Martin\_Krizek](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@Martin\_Krizek](https://forum.ansible.com/u/Martin_Krizek)\
**Post date:** [January 28, 2020, 1:16pm UTC](https://forum.ansible.com/t/help-with-meta-end-host/31324/3 "2020-01-28T13:16:28Z")

</div>

Hello,

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

Thanks!  
Martin
