# Getting Runtime error “obj must be a list of dicts or a nested dict” using with\_items

**URL:** <https://forum.ansible.com/t/getting-runtime-error-obj-must-be-a-list-of-dicts-or-a-nested-dict-using-with-items/31064>\
**Category:** Ansible Project\
**Created:** [August 17, 2019, 4:37am UTC](https://forum.ansible.com/t/getting-runtime-error-obj-must-be-a-list-of-dicts-or-a-nested-dict-using-with-items/31064 "2019-08-17T04:37:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Easy\_King](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@Easy\_King](https://forum.ansible.com/u/Easy_King)\
**Post date:** [August 17, 2019, 4:37am UTC](https://forum.ansible.com/t/getting-runtime-error-obj-must-be-a-list-of-dicts-or-a-nested-dict-using-with-items/31064/1 "2019-08-17T04:37:16Z")

</div>

I need to search a string “TicketID” in .db files under a directory. If found my playbook should fail.

Below is my playbook for the same, however I’m getting runtime error “using with\_items”

Output:

> TASK [Search for Number] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [45.72.65.99]: FAILED! =\> {“msg”: “obj must be a list of dicts or a nested dict”}

Below is my ansible playbook’s task:

`

- name: find multiple .db files under a given location  
find:  
paths: “{{ BASEPATH }}”  
patterns: “\*.db”  
recurse: yes  
register: files\_matched

- name: "Search for Number  
command: “grep -i {{ TicketID }} {{ item.path }}”  
register: command\_result  
failed\_when: command\_result.rc == 0  
with\_items:

- “{{ files\_matched.files }}”  
`

I tried using loop instead of with\_items as below but that too did not work

`

- name: "Search for Number  
command: “grep -i {{ TicketID }} {{ item.1.path }}”  
register: command\_result  
failed\_when: command\_result.rc == 0  
loop: “{{ files\_matched.results | subelements(‘files’) }}”  
`

Output:

> TASK [Search for Number] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [45.72.65.99]: FAILED! =\> {“msg”: “obj must be a list of dicts or a nested dict”}

I also tried using json\_query like below but I still get error:

`

- name: “Search for Number”  
command: “grep -i {{ TicketID }} {{ item }}”  
register: command\_result  
failed\_when: command\_result.rc == 0  
loop: “{{ files\_matched.files|json\_query(‘.path’) }}”  
`

Output:

> TASK [Search for Number] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [45.72.65.99]: FAILED! =\> {“msg”: “Invalid data passed to ‘loop’, it requires a list, got this instead: . Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup.”}

I would like to understand why is this playbook failing and how I can fix it.

---

<div class="post-metadata">

**Author:** ![Asha\_Omanakuttan](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@Asha\_Omanakuttan](https://forum.ansible.com/u/Asha_Omanakuttan)\
**Post date:** [August 19, 2019, 12:27pm UTC](https://forum.ansible.com/t/getting-runtime-error-obj-must-be-a-list-of-dicts-or-a-nested-dict-using-with-items/31064/2 "2019-08-19T12:27:59Z")

</div>

you have opened double quotes and not closed it.

- name: "Search for Number
