I am trying to modify file name after fetching it from its path using basename in Ansible, I was successfully able to remove extension from name, but unable to achieve next target
Path: /bin/data/xyzzz_no_db_20.9.1-82.tgz
(i.e: xyzzz_no_db_20.9.1-82.tgz => xyzzzz_no_db_20.9.1-82 => xyzzz_no_db:20.9.1-82.(Final outcome expected)
Basically, need to replace last occurence of (_)(underscore) with (:)(coln), and tried same by using code mentioned below, their must be some modification required.
Thanks in Advance.
- name: Modify image name
set_fact:
imagename: " {{ latest_file.path | basename | regex_replace('.tgz', '') | regex_replace('/^[^_^_]*[0-9]/',':')}}"