# run with\_items loop using python api.

**URL:** <https://forum.ansible.com/t/run-with-items-loop-using-python-api/35629>\
**Category:** Ansible Developer\
**Created:** [August 17, 2021, 10:22am UTC](https://forum.ansible.com/t/run-with-items-loop-using-python-api/35629 "2021-08-17T10:22:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Google\_Pixel](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@Google\_Pixel](https://forum.ansible.com/u/Google_Pixel)\
**Post date:** [August 17, 2021, 10:22am UTC](https://forum.ansible.com/t/run-with-items-loop-using-python-api/35629/1 "2021-08-17T10:22:01Z")

</div>

for a bigger project we are interfacing ansible with python using the python api.

however I am not able to run the debug module using a with\_items loop.  
the purpose is to find/report and delete the files found on remote systems.

play\_source = dict(  
name=“Ansible Play”,  
hosts=‘all’,  
gather\_facts=‘no’,  
vars=dict(sudo\_content=sudoers\_content),  
tasks=[  
dict(action=dict(module=‘find’,  
file\_type=‘file’,  
paths = ‘/etc’,  
age= ‘14d’,  
use\_regex = ‘True’,  
patterns=‘sudoers(?=\.).\*’), register=‘output’),  
dict(action=dict(module=‘debug’, args=dict(msg=‘{{ item.path}}’), with\_items=‘{{ output.files}}’))

]  
)

this executes fine the files are found but the debug task fails due to item variable is undefined.

fatal: [vm]: FAILED! =\>  
msg: ‘The task includes an option with an undefined variable. The error was: ‘‘item’’ is undefined’

how can i make the loop work?

thanks
