I need to rename /jp/Test to /jp/test only if /jp/Test exists , otherwise i dont need to perform this task. if Both exists i need to merge both into /jp/test
hosts: test
gather_facts: false
vars:
hostsfiles:
- /jp/test
- /jp/Test
tasks:
- name: Check if file exists
stat:
path: "{{ item}}"
with_items: "{{ hostsfiles }}"
register: jpresult
- name: test
shell: mv "{{item.2.stat.path}}" /jp/test
with_items:
- "{{ jpresult.results }}"
when: item.1.stat.exists == false and item.2.stat.exists == true