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.