Download Multiple files from same location but with different names

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

Use

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

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

Little syntax correction -

.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.

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

I think you’re looking for something like this:

**---** **- 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.

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

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

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

Each item will then be one line from the file.

Thanks Todd.

Let me try it and shall keep you posted.

Regards
Amit