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

**URL:** <https://forum.ansible.com/t/msg-ansibleundefinedvariable-one-or-more-undefined-variables-list-object-has-no-element-1-failed-true/18054>\
**Category:** Ansible Project\
**Created:** [April 22, 2015, 4:48pm UTC](https://forum.ansible.com/t/msg-ansibleundefinedvariable-one-or-more-undefined-variables-list-object-has-no-element-1-failed-true/18054 "2015-04-22T16:48:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chanaka\_Samarajeewa](https://avatars.discourse-cdn.com/v4/letter/c/4da419/32.png) [@Chanaka\_Samarajeewa](https://forum.ansible.com/u/Chanaka_Samarajeewa)\
**Post date:** [April 22, 2015, 4:48pm UTC](https://forum.ansible.com/t/msg-ansibleundefinedvariable-one-or-more-undefined-variables-list-object-has-no-element-1-failed-true/18054/1 "2015-04-22T16:48:16Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 22, 2015, 7:40pm UTC](https://forum.ansible.com/t/msg-ansibleundefinedvariable-one-or-more-undefined-variables-list-object-has-no-element-1-failed-true/18054/2 "2015-04-22T19:40:51Z")

</div>

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.
