---
- hosts:
etl12.example.com remote_user: ansible
become: yes
become_user: root
become_method: sudo
gather_facts: yes
connection: ssh
tasks:
- name: Update file in remote server
block:
- name: find ICM files
find:
path: /data1/dw/ftpuser/Varicent_Files/ICM_CC
patterns: "*.csv"
register: ICM_CC_FILE
- name: update to file
lineinfile:
path: /data1/dw/ftpuser/Varicent_Files/ICM_CC/ICM_Transfer_History
state: present
create: yes
line: "{{ item.path }}"
register: ICM_CC_file_update
with_items:
- "{{ ICM_CC_FILE.files }}"
delegate_to:
etl12.example.com - debug:
msg: "{{ ICM_CC_FILE.files }}"
when: ICM_CC_file_update.changed
- name: Transfer files from remote to Local
fetch:
src: "{{ item.path }}"
dest: /tmp/
flat: yes
with_items:
- "{{ tarfilename.files }}"
- debug:
msg: "{{ ICM_CC_FILE.files }}"
when: ICM_CC_file_update.changed
- debug: var=item.path
with_items: "{{ ICM_CC_FILE.files }}"