# Download Multiple files from same location but with different names

**URL:** <https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079>\
**Category:** Ansible Project\
**Created:** [June 9, 2023, 7:23pm UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079 "2023-06-09T19:23:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amit\_Kulkarni](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@Amit\_Kulkarni](https://forum.ansible.com/u/Amit_Kulkarni)\
**Post date:** [June 9, 2023, 7:23pm UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079/1 "2023-06-09T19:23:22Z")

</div>

Hello All,

I have the below playbook, I wanted to download the files from gitlab on same path with different names. I have below playbook,  
As can seen below source path is same but file name is different, I need to have src path defined and should mention only file names in loop or may be i can read these names from different file itself.

Appreciate any help with this

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [June 9, 2023, 7:37pm UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079/2 "2023-06-09T19:37:50Z")

</div>

Use

dest: “/busdata/qwm/mna1/geodev12/folders/GX/PATCH/{{ item | basename }}”

---

<div class="post-metadata">

**Author:** ![Amit\_Kulkarni](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@Amit\_Kulkarni](https://forum.ansible.com/u/Amit_Kulkarni)\
**Post date:** [June 9, 2023, 8:20pm UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079/3 "2023-06-09T20:20:42Z")

</div>

Hello Abhijit,

Thanks for your help, I came up with another one, if you could provide your input that would be great.  
Please let me know is this looking ok, what I am trying to do is t

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [June 9, 2023, 10:28pm UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079/4 "2023-06-09T22:28:39Z")

</div>

Little syntax correction -

---

<div class="post-metadata">

**Author:** ![Amit\_Kulkarni](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@Amit\_Kulkarni](https://forum.ansible.com/u/Amit_Kulkarni)\
**Post date:** [June 10, 2023, 7:31pm UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079/5 "2023-06-10T19:31:57Z")

</div>

.Hello All,

Can someone please help with below.

I need to read the filename from an external file in ansible playbook, if someone has done something like this before please let me know.

In the loop there are DAT files which will be changing every time, so I need to keep those in an external file and read it in the main playbook.

Appreciate your help.

---

<div class="post-metadata">

**Author:** ![Amit\_Kulkarni](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@Amit\_Kulkarni](https://forum.ansible.com/u/Amit_Kulkarni)\
**Post date:** [June 10, 2023, 10:33pm UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079/6 "2023-06-10T22:33:58Z")

</div>

Hello All,

I am trying to work my way through this playbook, here is what I got so far, appreciate your input and let me know if this is correct…

Problem now is patches.txt will also be in same in repos as the actual files, so I am not sure how to provide the path to that file

Appreciate all your inputs here

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [June 10, 2023, 11:26pm UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079/7 "2023-06-10T23:26:23Z")

</div>

I think you’re looking for something like this:

```auto
**---**  **- name: Download the patches for sage**  **hosts: app**  **vars:**  **my_dest: /busdata/qwm/mna1/geodev12/folders/GX/PATCH/** **my_url: [https://raw.gitlabusercontent.michelin.com/na-sc/na-log/wms_nca/wms_na_patch/sagepatch/](https://raw.gitlabusercontent.michelin.com/na-sc/na-log/wms_nca/wms_na_patch/sagepatch/)**  **tasks:**  **- name: Download files from my_url**  **ansible.builtin.get_url:**  **url: "{{ my_url }}/{{ item }}"**  **url_username:**  **url_password:**  **dest: "{{ my_dest }}/{{ item }}"**  **register: download**  **until: download is succeeded**  **delay: 3** **loop: "{{ lookup('ansible.builtin.file', 'patches.txt') | split('\n') }}"**

```

If your “patches.txt” file is part of your source repo anyway, you could list the patches in a “group\_vars/app.yml” file and use the containing variable directly. There are lots of other ways to do it as well.

---

<div class="post-metadata">

**Author:** ![Amit\_Kulkarni](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@Amit\_Kulkarni](https://forum.ansible.com/u/Amit_Kulkarni)\
**Post date:** [June 10, 2023, 11:48pm UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079/8 "2023-06-10T23:48:25Z")

</div>

Thanks Todd.

If i keep the text file on remote server will the above work?.  
I can provide the full path for the file in lookup and it will get picked up one by one

Regards  
Amit

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [June 11, 2023, 1:33am UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079/9 "2023-06-11T01:33:52Z")

</div>

No. Lookups happen on the Ansible controller.

If the file is on the remote host(s), then prior to the task where you need the data, do an **ansible.builtin.command** task which ` **cat** `s the file and registers the result. Then on the “ **Download the patches** ” task, say

```auto
    **loop: "{{** <b>*registered_cat*</b> **.stdout_lines }}"**

```

Each item will then be one line from the file.

---

<div class="post-metadata">

**Author:** ![Amit\_Kulkarni](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@Amit\_Kulkarni](https://forum.ansible.com/u/Amit_Kulkarni)\
**Post date:** [June 11, 2023, 1:52am UTC](https://forum.ansible.com/t/download-multiple-files-from-same-location-but-with-different-names/38079/10 "2023-06-11T01:52:23Z")

</div>

Thanks Todd.

Let me try it and shall keep you posted.

Regards  
Amit
