---
# 1. PRE-CLEANUP: Wipe out the "graveyard" of old migration folders
- name: "Cleanup: Find all legacy migration directories in /tmp"
ansible.builtin.find:
paths: "/tmp"
patterns: "*-leonid-comet-lse-migration"
file_type: directory
register: old_migration_folders
- name: "Cleanup: Remove old migration staging areas"
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ old_migration_folders.files }}"
# THE GUARD: Skip the current build folder so we don't delete our source
when: "lightspeed.build_version not in item.path"
become: yes
# 2. DISCOVERY: Locate the RPM
- name: "Discovery: Find the current RPM file"
ansible.builtin.find:
paths: "/tmp/{{ lightspeed.build_version }}"
patterns: "*.rpm"
register: found_rpms
# 3. LOGIC: Extract Prefix and Version
- name: "Logic: Extract Metadata from RPM Filename"
ansible.builtin.set_fact:
rpm_filename: "{{ found_rpms.files[0].path | basename }}"
app_prefix: "{{ (found_rpms.files[0].path | basename | regex_search('^([^-]+)-(.*)\\.x86_64\\.rpm$', '\\1'))[0] }}"
app_version: "{{ (found_rpms.files[0].path | basename | regex_search('^([^-]+)-(.*)\\.x86_64\\.rpm$', '\\2'))[0] }}"
when: found_rpms.matched > 0
# 4. REPORT: Show extracted metadata (The step you requested)
- name: "Report: Show Discovered Deployment Metadata"
ansible.builtin.debug:
msg:
- "Full RPM Filename: {{ rpm_filename }}"
- "Detected App/Region: {{ app_prefix }}"
- "Detected Version: {{ app_version }}"
# 5. INSTALLATION: Automatic Unpack via YUM
- name: "Install: Unpack RPM via Built-in Module"
ansible.builtin.yum:
name: "{{ found_rpms.files[0].path }}"
state: present
disable_gpg_check: yes
become: yes
# 6. LINK: Dynamic Symlink Creation
- name: "Link: Create symlink /opt/CPLS/live -> /opt/{{ app_prefix }}/{{ app_version }}"
ansible.builtin.file:
src: "/opt/{{ app_prefix }}/{{ app_version }}"
dest: "/opt/CPLS/live"
state: link
force: yes
become: yes
# 7. VERIFICATION: List contents of the new link
- name: "Verification: List content of the symbolic link"
ansible.builtin.command:
cmd: "ls -ltr /opt/CPLS/live/"
register: symlink_contents
become: yes
# noqa command-instead-of-module
- name: "Verification: Display results"
ansible.builtin.debug:
var: symlink_contents.stdout_lines
# 8. POST-CLEANUP: Delete the current staging directory
- name: "Cleanup: Delete current staging directory"
ansible.builtin.file:
path: "/tmp/{{ lightspeed.build_version }}/"
state: absent
become: yes
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)