# Performing action on list items inside another loop

**URL:** <https://forum.ansible.com/t/performing-action-on-list-items-inside-another-loop/34094>\
**Category:** Ansible Project\
**Created:** [October 23, 2020, 5:02pm UTC](https://forum.ansible.com/t/performing-action-on-list-items-inside-another-loop/34094 "2020-10-23T17:02:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akshay\_Kumar](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@Akshay\_Kumar](https://forum.ansible.com/u/Akshay_Kumar)\
**Post date:** [October 23, 2020, 5:02pm UTC](https://forum.ansible.com/t/performing-action-on-list-items-inside-another-loop/34094/1 "2020-10-23T17:02:05Z")

</div>

Hi guys,

Please provide your advise on below scenario:

Finding files and putting in a list code -----

- name: find Files to move  
find:  
paths: ‘{{ item.VlclDirName }}’  
patterns: ‘{{ item.VlclFileSpec }}’  
register: filesfound  
when: item.VlclDirName is defined and item.VlclUser == VlclCmdLineUser  
loop: “{{ lookup(‘vars’, VinWindow)[‘mv’] }}”

- name: Parse into list  
set\_fact:  
results\_list: “{{ filesfound.results | map(attribute=‘files’) | sum(start=) | map(attribute=‘path’) | list }}”

output for the above list:

ok: [localhost] =\> {  
“ansible\_facts”: {  
“results\_list”: [  
“/tmp/DevFileTestLocation/lets.log”,  
“/tmp/DevFileTestLocation/see.log”  
]  
},  
“changed”: false  
}

Using the results\_list in another loop as below :

- name: setting variable for trget directory  
set\_fact:  
VlclTgtDir: ‘{{ item.VlclTgtDir }}’  
VlclMvCode: “{{ ‘DTG’ if (VlclTgtDir == ’ ') else VlclTgtDir }}”  
shell: mv “{{ results\_list.item }}” “{{ VlclMvCode}}”  
when: item.VlclDirName is defined and item.VlclUser == VlclCmdLineUser  
loop: “{{ lookup(‘vars’, VinWindow)[‘mv’] }}”

Here a lookup is being done in loop for checking cfg file and fetching values of list where key is ‘MV’

The above code is not working and i would appreciate if someone can tell me of a way to do the shell move command with items of results\_list within loop of cfg file values.

Thanks.
