I am installing nexus using Ansible. Ansible task downloads the last version packed as "tar.gz" archive and unpacks it into the target directory. The archive contains two directories. For example:
/srv
|- /nexus-3.34.0-01
|- /sonatype-work
Then Ansible need to create a symbolic link. Like this:
/srv
|- /nexus-3.34.0-01
|- /sonatype-work
|- ~nexus -> /srv/nexus-3.34.0-01
Ansible don't know the name of the nexus directory. It is not a problem, if we have only one of them:
- name : Find the name of the nexus directory
ansible.builtin.find:
paths: /srv
patterns: 'nexus-*'
file_type: directory
register: nexus_dir
- name: Create a symbolic link for Nexus
ansible.builtin.file:
src: "{{ nexus_dir.files[0].path }}"
dest: /srv/nexus
state: link
THE PROBLEM IS: The directory srv already contains previous nexus installations. How can I look into the original archive to find the name of the current nexus directory?
Here is the solution I found:
where
grep -o -E -m 1returns the first match of the provided regular expression.