when: inventory_hostname != play_hosts[-1] not working

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