# Programmatically checking if a particular host is still a target.

**URL:** <https://forum.ansible.com/t/programmatically-checking-if-a-particular-host-is-still-a-target/18903>\
**Category:** Ansible Project\
**Created:** [July 30, 2015, 3:20pm UTC](https://forum.ansible.com/t/programmatically-checking-if-a-particular-host-is-still-a-target/18903 "2015-07-30T15:20:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jang](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@jang](https://forum.ansible.com/u/jang)\
**Post date:** [July 30, 2015, 3:20pm UTC](https://forum.ansible.com/t/programmatically-checking-if-a-particular-host-is-still-a-target/18903/1 "2015-07-30T15:20:05Z")

</div>

So I've a situation where I want to delegate\_to a host. That host is one  
(arbitrarily chosen) of a group.

Rather than

delegate\_to: "{{ GROUP[0] }}"

I'd like to confirm that the host is actually up, first - or rather, pick  
an arbitrary member of GROUP that's successfully had facts gathered  
against it (and no previous play fail on it).

Is that kind of status derivable from any of the information that ansible  
currently exposes as a variable to the J2 engine? (Or any other way: if I  
need to write a custom filter for this job I have no objection to doing  
so.)

Cheers,  
jan

---

<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:** [July 30, 2015, 3:54pm UTC](https://forum.ansible.com/t/programmatically-checking-if-a-particular-host-is-still-a-target/18903/2 "2015-07-30T15:54:35Z")

</div>

I think this may help;

{{ play\_hosts[0] }}

That should pick the first host in the current play (so no previous failures)

---

<div class="post-metadata">

**Author:** ![jang](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@jang](https://forum.ansible.com/u/jang)\
**Post date:** [August 4, 2015, 4:25pm UTC](https://forum.ansible.com/t/programmatically-checking-if-a-particular-host-is-still-a-target/18903/3 "2015-08-04T16:25:30Z")

</div>

Hrm, it would, but the group that's being targeted by the top-level  
playbook is not the same as the group that contains candidate hosts that  
I'd like to delegate to - unless I misunderstand what play\_hosts is doing.
