# end\_host not working as expected

**URL:** <https://forum.ansible.com/t/end-host-not-working-as-expected/31277>\
**Category:** Ansible Project\
**Created:** [September 13, 2019, 5:13pm UTC](https://forum.ansible.com/t/end-host-not-working-as-expected/31277 "2019-09-13T17:13:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpowell](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dpowell](https://forum.ansible.com/u/dpowell)\
**Post date:** [September 13, 2019, 5:13pm UTC](https://forum.ansible.com/t/end-host-not-working-as-expected/31277/1 "2019-09-13T17:13:15Z")

</div>

Both end\_host and end\_play seem to both cause the job to skip all hosts. I know that only one host meets the condition so it should execute on 1 but exits for both. Am I missing something? I thought end\_host would only end the play for the host that meets the when condition.

`

tasks:

- name: Pre java-1.8._-openjdk package check  
raw: rpm -qa java-1.8._-openjdk | wc -l  
register: package\_precheck

- block:

- name: “end play for host host if nothing to upgrade”  
debug:  
msg: “nothing to upgrade, ending play for host”

- meta: end\_host  
when: package\_precheck.stdout \> 0

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 14, 2019, 9:25am UTC](https://forum.ansible.com/t/end-host-not-working-as-expected/31277/2 "2019-09-14T09:25:50Z")

</div>

You should add a this debug  
&nbsp;&nbsp;- debug: var=package\_precheck

Then you'll see that stdout is a string not an int, so filter the variable through int

&nbsp;&nbsp;when: package\_precheck.stdout | int \> 0

---

<div class="post-metadata">

**Author:** ![dpowell](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dpowell](https://forum.ansible.com/u/dpowell)\
**Post date:** [September 14, 2019, 3:12pm UTC](https://forum.ansible.com/t/end-host-not-working-as-expected/31277/3 "2019-09-14T15:12:58Z")

</div>

Thank you Kai, I ran in debug noticed it was a string. I updated the command but end\_host still kills the entire run for all hosts. I have 2 for testing.

“stdout”: “1”,  
“stdout”: “0”,

Above is the output. From that I’d expect the first host to be skipped and the 2nd host to continue to execute. At least that is how I’m reading end\_host should work. end\_play sounds like what is being used I’ve tried both, both behave the same.

---

<div class="post-metadata">

**Author:** ![dpowell](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dpowell](https://forum.ansible.com/u/dpowell)\
**Post date:** [September 14, 2019, 3:43pm UTC](https://forum.ansible.com/t/end-host-not-working-as-expected/31277/4 "2019-09-14T15:43:43Z")

</div>

I think its working now. I think part of my issue was that one of the host had python 2.4 and all the error messages from that was throwing me off. Changed that test node out for a diff one and the logic appears to be working now after changing \> 0 to int \> 0.

Thanks for the help Kai.

---

<div class="post-metadata">

**Author:** ![dpowell](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dpowell](https://forum.ansible.com/u/dpowell)\
**Post date:** [September 14, 2019, 3:55pm UTC](https://forum.ansible.com/t/end-host-not-working-as-expected/31277/5 "2019-09-14T15:55:35Z")

</div>

This was also throwing me off, it would be nice if there was a way around it as well.

Even though the logic is working and node1 stops after the check, the block output displays the same msg for all hosts. I would have thought that this would only show the msg for node1 as thats the node thta meets the end\_host check. Node2 continues to run all other checks but the message is confusing as it first looks like its skipping both hosts but its really not.

`

TASK [end play for host host if nothing to upgrade] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[node1.test.com](http://node1.test.com)] =\> {  
“msg”: “Nothing to upgrade, ending play for host”  
}  
ok: [[node2.test.com](http://node2.test.com)] =\> {  
“msg”: “Nothing to upgrade, ending play for host”  
}

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 14, 2019, 10:02pm UTC](https://forum.ansible.com/t/end-host-not-working-as-expected/31277/6 "2019-09-14T22:02:57Z")

</div>

> This was also throwing me off, it would be nice if there was a way around  
> it as well.
> 
> Even though the logic is working and node1 stops after the check, the block  
> output displays the same msg for all hosts. I would have thought that this  
> would only show the msg for node1 as thats the node thta meets the end\_host  
> check. Node2 continues to run all other checks but the message is confusing  
> as it first looks like its skipping both hosts but its really not.
> 
> TASK [end play for host host if nothing to upgrade]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [node1.test.com] =\> {  
> &nbsp;&nbsp;&nbsp;&nbsp;"msg": "Nothing to upgrade, ending play for host"  
> }  
> ok: [node2.test.com] =\> {  
> &nbsp;&nbsp;&nbsp;&nbsp;"msg": "Nothing to upgrade, ending play for host"  
> }

That's because your when: is indented to fare.  
It need to be on the same level as the block.

> > &nbsp;&nbsp;&nbsp;&nbsp;- block:  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: "end play for host host if nothing to upgrade"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug:  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "nothing to upgrade, ending play for host"
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- meta: end\_host  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: package\_precheck.stdout \> 0

As you can see, the when is only on meta task so the debug in the block will always run.
