Extracting parts of a string

I posted an answer for that in the last thread, you can use the basename filter to get just the filename and regex_replace filter to remove the start and the ends of the filename, for example, something like this:

- name: Set a fact for the Nexus version
  ansible.builtin.set_fact:
    nexus_version: >-
      {{ nexus_path |
      ansible.builtin.basename |
      ansible.builtin.regex_replace('^nexus-') |
      ansible.builtin.regex_replace('-unix[.]tar[.]gz$') }}
  vars:
    nexus_path: /opt/nexus/install/nexus-3.67.1-01-unix.tar.gz
3 Likes