{'msg': 'AnsibleUndefinedVariable: One or more undefined variables: list object has no element 1', 'failed': True}

Hello,

For some reason, when my group_vars list only has 1 item under “test2:” it get the following error. If I have more than 1 list item under “test2:” then everything works correctly. Is this an Ansible bug or do I need to do something differently?

{‘msg’: ‘AnsibleUndefinedVariable: One or more undefined variables: list object has no element 1’, ‘failed’: True}

group vars:

So lists have 0 based indices, if you try to access item '1' when the
list only has 1 item (really item '0') you will get this error.

I think this expression is the culprit:

{% set list_length = item.values()|length %}

as with_dict should return item.key and item.value, not sure what
item.values() is doing.