# Fetch the latest file only

**URL:** <https://forum.ansible.com/t/fetch-the-latest-file-only/27359>\
**Category:** Ansible Project\
**Created:** [April 24, 2018, 12:07pm UTC](https://forum.ansible.com/t/fetch-the-latest-file-only/27359 "2018-04-24T12:07:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bubul\_Medhi](https://avatars.discourse-cdn.com/v4/letter/b/90ced4/32.png) [@Bubul\_Medhi](https://forum.ansible.com/u/Bubul_Medhi)\
**Post date:** [April 24, 2018, 12:07pm UTC](https://forum.ansible.com/t/fetch-the-latest-file-only/27359/1 "2018-04-24T12:07:35Z")

</div>

Hi,

This is a simple ansible script to create a zip file with date and time.

I want to fetch only the latest zip file to the destination server. How do I fetch only the latest file ?

`

- hosts: all  
tasks:
- name: Ansible zip the configuration directory  
archive:  
path: /home/admin/jboss/standalone/configuration  
dest: /home/admin/jboss/standalone/configuration.{{ lookup(‘pipe’, ‘date +%Y%m%d%H%M%S’) }}.zip  
format: zip

`

Regards,  
Uday

---

<div class="post-metadata">

**Author:** ![Bubul\_Medhi](https://avatars.discourse-cdn.com/v4/letter/b/90ced4/32.png) [@Bubul\_Medhi](https://forum.ansible.com/u/Bubul_Medhi)\
**Post date:** [April 25, 2018, 6:57am UTC](https://forum.ansible.com/t/fetch-the-latest-file-only/27359/2 "2018-04-25T06:57:18Z")

</div>

no help ?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 25, 2018, 6:09pm UTC](https://forum.ansible.com/t/fetch-the-latest-file-only/27359/3 "2018-04-25T18:09:24Z")

</div>

Since the latest file you create is the latest one, store the lookup date in a variable with set\_fact then you know the filename to fetch.
