# when: inventory\_hostname != play\_hosts\[-1\] not working

**URL:** <https://forum.ansible.com/t/when-inventory-hostname-play-hosts-1-not-working/24969>\
**Category:** Ansible Project\
**Created:** [July 12, 2017, 8:35pm UTC](https://forum.ansible.com/t/when-inventory-hostname-play-hosts-1-not-working/24969 "2017-07-12T20:35:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrono](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@chrono](https://forum.ansible.com/u/chrono)\
**Post date:** [July 12, 2017, 8:35pm UTC](https://forum.ansible.com/t/when-inventory-hostname-play-hosts-1-not-working/24969/1 "2017-07-12T20:35:11Z")

</div>

Hello,

I’m trying to get a role to run on all hosts except the last. I thought this would work:

> - { role: wait, timeout: 300, tags: [‘wait’], when: inventory\_hostname != play\_hosts[-1] }

…but I get a YAML syntax error.

Is there a way to do this?

Best,

- C
