Check if arrays are defined and not empty in ansible


I have the following code

In the above code, groups[MY_HOSTNAME] is an array. What is the best way to check that groups[MY_HOSTNAME] is defined and also that it is not empty
If it is either of that I want the value to be assigned to MY_SERVER


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:

Leave a Reply