0

I have the below module to download files from source to destination. But now I am trying to set it up in such a way that if a 'directory' path is specified as 'src' instead of 'file', it should download all the files and directories under that path and replicate same on the destination.

Using win_uri with get_content might be a solution, but not sure how it can be done in a recursive way with replicating the same structure.

- name: get files
  win_get_url:
    url: "https://repo/browse/{{ item.src }}"
    dest: "{{ item.dest }}"
Zeitounator
  • 38,476
  • 7
  • 53
  • 66
reddy0969
  • 109
  • 1
  • 10
  • 1
    Protocol HTTP(S) and the module `win_get_url` don't automatically provide a recursive download. You need to write an HTML parser that extracts new URLs from every downloaded HTML file, compare the URLs with base, ignore external URLs and download/parse more HTML files. – phd Aug 25 '22 at 21:06
  • 2
    Most probably using a recursive downloader like `wget` would be much simpler. – phd Aug 25 '22 at 21:15
  • Which type of repo are you trying to parse on the other end? Do you know which software is managing it (nexus, artifactory, gittlab artifact repo......)? – Zeitounator Aug 26 '22 at 08:05
  • @Zeitounator its, GitHub – reddy0969 Aug 26 '22 at 15:21
  • @reddy0969 May be you just need `git clone --depth=1`? You can use https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html#ansible-collections-ansible-builtin-git-module – phd Aug 26 '22 at 15:28
  • `git archive --remote=https://repo main | tar -x -C /path/to/extract/dir` will do what you want. You can run the full command in a `shell` task. Or you can run the first part in a shell and push the result to a tar file then use the `unarchive` module to extract the file where you need. For more ideas, see https://stackoverflow.com/questions/13750182/git-how-to-archive-from-remote-repository-directly – Zeitounator Aug 26 '22 at 17:16
  • 1
    @Zeitounator `git archive --remote` doesn't work with GitHub. – phd Aug 26 '22 at 21:19

0 Answers0