Check if arrays are defined and not empty in ansible

I don’t know if it’s version specific, but I’m currently running ansible-2.3.2 on RHEL6 and I had to put quotes around the group name to get it to work for me:

when: groups["GROUP_NAME"] is defined and (groups["GROUP_NAME"]|length>0)

Edit: I couldn’t add this as a comment to techraf’s answer because I don’t have enough reputation.

Leave a Comment