Unarchive - using wildcards in 'src' option

Another approach would be to use the URI module to do a HEAD request to get the Location of the file and then get the filename from that, for example (untested):

- name: Check the latest version of Nexus 3
  ansible.builtin.uri:
    url: https://download.sonatype.com/nexus/3/latest-unix.tar.gz
    method: HEAD
    status_code: 302 
    follow_redirects: none
  check_mode: false
  changed_when: false
  register: nexus_headers

- name: Debug Nexus 3 latest headers
  ansible.builtin.debug:
    msg:
      - "Location: {{ nexus_headers.location }}"
      - "Path: {{ nexus_headers.location | ansible.builtin.urlsplit('path') }}"
      - "File: {{ nexus_headers.location | ansible.builtin.urlsplit('path') | ansible.builtin.basename }}"
      - "Version: {{ nexus_headers.location | ansible.builtin.urlsplit('path') | ansible.builtin.basename | ansible.builtin.regex_replace('^nexus-') | ansible.builtin.regex_replace('[.]tar[.]gz$') }}"

This approach might make sense if you want to only download an update if the specific version isn’t already installed. :person_shrugging:

1 Like