I’m writing a playbook for patching and in that i required 2 modules to Find and Copy the recently modified file in remote machine , I have tried with below modules, but not working! if someone have an idea, kindly share.
::-Find and copy
name: find recently modified file and copy it
find: path=/var/tmp/{{ansible_hostname}} patterns=“*.tar.xz”
When you don't get any answer the usual cause is that people don't understand you need or you have provided to little information.
Here we have little of both.
Hello,
I'm writing a playbook for patching and in that i required 2 modules to
Find and Copy the recently modified file in remote machine , I have tried
with below modules, but not working! if someone have an idea, kindly share.
You are saying copy but using fetch.
copy module in Ansible transferring a file(s) from Ansible controller to remote host.
fetch is transferring a file from remote host to the Ansible controller.
And your explanation doesn't say what you are actually trying to do.
Wild guess, you are trying to fetch a file from remote host to the Ansible controller?
When say it's not working, what is not working is always good to include in the post.
::-Find and copy
- name: find recently modified file and copy it
find: path=/var/tmp/{{ansible_hostname}} patterns="*.tar.xz"
- name: copy files
fetch: path=/var/tmp/{{ansible_hostname}} dest=/kdump/sosreport/ flat=yes
Here you use the find module, but not the result of it and the fetch would get the file /var/tmp/{{ansible_hostname}}
::- Try to find recently modified file.
First play
- name: find recently modified file and copy it
find:
path: "/var/tmp/{{ansible_hostname}}"
register: found_files
- name: Get latest file
set_fact:
latest_file: "{{ found_files.files | sort(attribute='mtime',age=-1h,reverse=true) | first }}"
Here you use the find and register the result, but don't use the result in fetch just set_fact.
Second play
- name: find recently modified file and copy it
find:
path: "/var/tmp/{{ansible_hostname}}"
register: found_files
- name: Get latest file
set_fact:
latest_file: "{{ found_files.files | sort(attribute='mtime',age=-1h,reverse=true) | first }}"
- name: print matches
debug:
msg: "{{ found_files.files }}"
Thank you for your response and sorry for the information which is not clear.
Actually I have a created playbook for patching, before patching i want to run sosreport and recently created sosreport.tar.xz should be copied on same remote machine into local folders, like from /var/tmp/hostname/sosreport/* to some NFS mount point!
So i’m looking for module like find & copy (to search recently modified file from specified folder on remote machine and that should be copied into specified folder.)
Thank you for your response and sorry for the information which is not
clear.
Actually I have a created playbook for patching, before patching i want to
run sosreport and recently created sosreport.tar.xz should be copied on
same remote machine into local folders, like from
/var/tmp/hostname/sosreport/* to some NFS mount point!
So i'm looking for module like find & copy (to search recently modified
file from specified folder on remote machine and that should be copied into
specified folder.)
You can use copy module to copy from and to the same host by setting "remote_src: yes"
The rest of it you already have, use the find module you had in you mail and add this copy